Class: PricingPlans::PlanResolution
- Inherits:
-
Struct
- Object
- Struct
- PricingPlans::PlanResolution
- Defined in:
- lib/pricing_plans/plan_resolution.rb
Constant Summary collapse
- SOURCES =
[:assignment, :subscription, :default].freeze
Instance Attribute Summary collapse
-
#assignment ⇒ Object
Returns the value of attribute assignment.
-
#plan ⇒ Object
Returns the value of attribute plan.
-
#source ⇒ Object
Returns the value of attribute source.
-
#subscription ⇒ Object
Returns the value of attribute subscription.
Instance Method Summary collapse
- #assignment? ⇒ Boolean
- #assignment_source ⇒ Object
- #default? ⇒ Boolean
-
#initialize(**attributes) ⇒ PlanResolution
constructor
A new instance of PlanResolution.
- #plan_key ⇒ Object
- #subscription? ⇒ Boolean
-
#to_h ⇒ Object
Extends Struct#to_h with derived fields.
Constructor Details
#initialize(**attributes) ⇒ PlanResolution
Returns a new instance of PlanResolution.
7 8 9 10 11 12 13 14 15 |
# File 'lib/pricing_plans/plan_resolution.rb', line 7 def initialize(**attributes) super unless SOURCES.include?(source) raise ArgumentError, "Invalid source: #{source.inspect}. Must be one of: #{SOURCES.inspect}" end freeze end |
Instance Attribute Details
#assignment ⇒ Object
Returns the value of attribute assignment
4 5 6 |
# File 'lib/pricing_plans/plan_resolution.rb', line 4 def assignment @assignment end |
#plan ⇒ Object
Returns the value of attribute plan
4 5 6 |
# File 'lib/pricing_plans/plan_resolution.rb', line 4 def plan @plan end |
#source ⇒ Object
Returns the value of attribute source
4 5 6 |
# File 'lib/pricing_plans/plan_resolution.rb', line 4 def source @source end |
#subscription ⇒ Object
Returns the value of attribute subscription
4 5 6 |
# File 'lib/pricing_plans/plan_resolution.rb', line 4 def subscription @subscription end |
Instance Method Details
#assignment? ⇒ Boolean
17 18 19 |
# File 'lib/pricing_plans/plan_resolution.rb', line 17 def assignment? source == :assignment end |
#assignment_source ⇒ Object
33 34 35 |
# File 'lib/pricing_plans/plan_resolution.rb', line 33 def assignment_source assignment&.source end |
#default? ⇒ Boolean
25 26 27 |
# File 'lib/pricing_plans/plan_resolution.rb', line 25 def default? source == :default end |
#plan_key ⇒ Object
29 30 31 |
# File 'lib/pricing_plans/plan_resolution.rb', line 29 def plan_key plan&.key end |
#subscription? ⇒ Boolean
21 22 23 |
# File 'lib/pricing_plans/plan_resolution.rb', line 21 def subscription? source == :subscription end |
#to_h ⇒ Object
Extends Struct#to_h with derived fields. Note: this preserves the raw plan / assignment / subscription objects.
39 40 41 42 43 44 |
# File 'lib/pricing_plans/plan_resolution.rb', line 39 def to_h super.merge( plan_key: plan_key, assignment_source: assignment_source ) end |