Skip to Content Skip to Search
Methods
A
C
D
I
M

Instance Public methods

available_with_plan_change(planning_created_at_epoch, available_at_epoch)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 76
def available_with_plan_change(planning_created_at_epoch, available_at_epoch)
  planning_created_at_epoch.gt(day_before_epoch).and(
    planning_created_at_epoch.lteq(day_of_epoch)
  ).and(
    available_at_epoch.lteq(day_before_epoch)
  )
end

content_in_search_period(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 5
def content_in_search_period(model)
  drip_in_search_period(model)
    .or(days_until_drip_in_search_period(model))
    .or(immediate_in_search_period(model))
    .or(immediate_with_plan_change(model))
    .or(drip_with_member_plan_change(model))
    .or(drip_with_content_plan_change(model))
    .or(days_until_drip_with_content_plan_change(model))
end

content_is_immediate(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 102
def content_is_immediate(model)
  drip_start = model.arel_table[:drip_start]
  days_until_drip = model.arel_table[:days_until_drip]

  drip_start.eq(nil).and(days_until_drip.eq(nil))
end

content_planning_created_at()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 124
def content_planning_created_at
  content_plannings_table[:created_at]
end

content_planning_created_at_epoch()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 128
def content_planning_created_at_epoch
  convert_to_epoch(content_planning_created_at)
end

convert_to_epoch(node)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 140
def convert_to_epoch(node)
  return Arel::Nodes::Quoted.new(node.to_f) if node.respond_to?(:to_f)

  epoch = Arel::Nodes::Quoted.new("epoch")

  Arel::Nodes::NamedFunction.new(
    "date_part", [epoch, node]
  )
end

day_before_epoch()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 116
def day_before_epoch
  convert_to_epoch(search_time - search_period)
end

day_of_epoch()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 120
def day_of_epoch
  convert_to_epoch(search_time)
end

days_until_drip_in_search_period(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 27
def days_until_drip_in_search_period(model)
  member_start_drip_epoch = convert_to_epoch(calculate_member_start_drip(model))
  drip_start = model.arel_table[:drip_start]

  conditions = drip_start.eq(nil)
    .and(
      member_start_drip_epoch.gt(day_before_epoch)
      .and(member_start_drip_epoch.lteq(day_of_epoch))
    )

  Arel::Nodes::Grouping.new(conditions)
end

days_until_drip_with_content_plan_change(model)

This doesn’t calculate the date correctly when there are multiple member start plans. It should use the oldest plan by member sign up instead of the oldest plan that by connection between member & signup. To resolve this another join has to be made oredered by member planning created_at.

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 89
def days_until_drip_with_content_plan_change(model)
  drip_start = model.arel_table[:drip_start]
  member_start_drip_epoch = convert_to_epoch(calculate_member_start_drip(model))

  conditions = drip_start.eq(nil).and(
    available_with_plan_change(
      content_planning_created_at_epoch, member_start_drip_epoch
    )
  )

  Arel::Nodes::Grouping.new(conditions)
end

drip_in_search_period(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 15
def drip_in_search_period(model)
  drip_start_epoch = convert_to_epoch(model.arel_table[:drip_start])

  conditions = drip_start_epoch.gt(
    day_before_epoch
  ).and(
    drip_start_epoch.lteq(day_of_epoch)
  )

  Arel::Nodes::Grouping.new(conditions)
end

drip_with_content_plan_change(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 64
def drip_with_content_plan_change(model)
  drip_with_plan_change(model, content_planning_created_at_epoch)
end

drip_with_member_plan_change(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 60
def drip_with_member_plan_change(model)
  drip_with_plan_change(model, member_planning_created_at_epoch)
end

drip_with_plan_change(model, planning_created_at_epoch)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 68
def drip_with_plan_change(model, planning_created_at_epoch)
  drip_start_epoch = convert_to_epoch(model.arel_table[:drip_start])

  Arel::Nodes::Grouping.new(
    available_with_plan_change(planning_created_at_epoch, drip_start_epoch)
  )
end

immediate_in_search_period(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 40
def immediate_in_search_period(model)
  conditions = content_is_immediate(model)
    .and(content_planning_created_at_epoch.gt(day_before_epoch))
    .and(content_planning_created_at_epoch.lteq(day_of_epoch))

  Arel::Nodes::Grouping.new(conditions)
end

immediate_with_plan_change(model)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 48
def immediate_with_plan_change(model)
  conditions = content_is_immediate(model).and(
    member_planning_created_at_epoch.gt(day_before_epoch).and(
      member_planning_created_at_epoch.lteq(day_of_epoch)
    )
  ).and(
    content_planning_created_at_epoch.lteq(day_before_epoch)
  )

  Arel::Nodes::Grouping.new(conditions)
end

member_planning_created_at()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 132
def member_planning_created_at
  member_plannings_table[:created_at]
end

member_planning_created_at_epoch()

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 136
def member_planning_created_at_epoch
  convert_to_epoch(member_planning_created_at)
end

member_start_drip(content)

# File engines/member/app/actions/member/content_search/scope/search_period.rb, line 109
def member_start_drip(content)
  cast_to_date = calculate_member_start_drip(content)
  expression_alias = Arel::Nodes::SqlLiteral.new("member_start_drip")

  Arel::Nodes::As.new(cast_to_date, expression_alias)
end