Class: PricingPlans::Assignment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/pricing_plans/models/assignment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assign_plan_to(plan_owner, plan_key, source: "manual") ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/pricing_plans/models/assignment.rb', line 45

def self.assign_plan_to(plan_owner, plan_key, source: "manual")
  LegacyPlanAssignmentApi.create_or_update_override!(
    plan_owner,
    plan_key,
    source: source,
    called_method_name: "PricingPlans::Assignment.assign_plan_to"
  )
end

.clear_pricing_plan_override_for!(plan_owner) ⇒ Object



38
39
40
41
42
43
# File 'lib/pricing_plans/models/assignment.rb', line 38

def self.clear_pricing_plan_override_for!(plan_owner)
  where(
    plan_owner_type: plan_owner.class.name,
    plan_owner_id: plan_owner.id
  ).destroy_all
end

.create_or_update_pricing_plan_override_for!(plan_owner, plan_key, source:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pricing_plans/models/assignment.rb', line 23

def self.create_or_update_pricing_plan_override_for!(plan_owner, plan_key, source:)
  assignment = find_or_initialize_by(
    plan_owner_type: plan_owner.class.name,
    plan_owner_id: plan_owner.id
  )

  assignment.assign_attributes(
    plan_key: plan_key.to_s,
    source: source.to_s
  )

  assignment.save!
  assignment
end

.remove_assignment_for(plan_owner) ⇒ Object



54
55
56
57
58
59
# File 'lib/pricing_plans/models/assignment.rb', line 54

def self.remove_assignment_for(plan_owner)
  LegacyPlanAssignmentApi.clear_override!(
    plan_owner,
    called_method_name: "PricingPlans::Assignment.remove_assignment_for"
  )
end

Instance Method Details

#planObject



19
20
21
# File 'lib/pricing_plans/models/assignment.rb', line 19

def plan
  Registry.plan(plan_key.to_sym)
end