Class: PricingPlans::PlanResolution

Inherits:
Struct
  • Object
show all
Defined in:
lib/pricing_plans/plan_resolution.rb

Constant Summary collapse

SOURCES =
[:assignment, :subscription, :default].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#assignmentObject

Returns the value of attribute assignment

Returns:

  • (Object)

    the current value of assignment



4
5
6
# File 'lib/pricing_plans/plan_resolution.rb', line 4

def assignment
  @assignment
end

#planObject

Returns the value of attribute plan

Returns:

  • (Object)

    the current value of plan



4
5
6
# File 'lib/pricing_plans/plan_resolution.rb', line 4

def plan
  @plan
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



4
5
6
# File 'lib/pricing_plans/plan_resolution.rb', line 4

def source
  @source
end

#subscriptionObject

Returns the value of attribute subscription

Returns:

  • (Object)

    the current value of subscription



4
5
6
# File 'lib/pricing_plans/plan_resolution.rb', line 4

def subscription
  @subscription
end

Instance Method Details

#assignment?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pricing_plans/plan_resolution.rb', line 17

def assignment?
  source == :assignment
end

#assignment_sourceObject



33
34
35
# File 'lib/pricing_plans/plan_resolution.rb', line 33

def assignment_source
  assignment&.source
end

#default?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/pricing_plans/plan_resolution.rb', line 25

def default?
  source == :default
end

#plan_keyObject



29
30
31
# File 'lib/pricing_plans/plan_resolution.rb', line 29

def plan_key
  plan&.key
end

#subscription?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pricing_plans/plan_resolution.rb', line 21

def subscription?
  source == :subscription
end

#to_hObject

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