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



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.assign_plan_to(plan_owner, plan_key, source: "manual")
  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



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

def self.remove_assignment_for(plan_owner)
  where(
    plan_owner_type: plan_owner.class.name,
    plan_owner_id: plan_owner.id
  ).destroy_all
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