Class: Recurly::Subscription::AddOns
- Inherits:
-
Object
- Object
- Recurly::Subscription::AddOns
show all
- Defined in:
- lib/recurly/subscription/add_ons.rb
Instance Method Summary
collapse
Constructor Details
#initialize(subscription, add_ons = []) ⇒ AddOns
Returns a new instance of AddOns.
10
11
12
13
|
# File 'lib/recurly/subscription/add_ons.rb', line 10
def initialize subscription, add_ons = []
@subscription, @add_ons = subscription, []
add_ons and add_ons.each { |a| self << a }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/recurly/subscription/add_ons.rb', line 64
def method_missing name, *args, &block
if @add_ons.respond_to? name
return @add_ons.send name, *args, &block
end
super
end
|
Instance Method Details
#<<(add_on) ⇒ self
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/recurly/subscription/add_ons.rb', line 25
def << add_on
case add_on
when AddOn then add_on = { :add_on_code => add_on.add_on_code }
when String, Symbol then add_on = { :add_on_code => add_on.to_s }
end
exist = @add_ons.find { |a| a[:add_on_code] == add_on[:add_on_code] }
if exist
exist[:quantity] ||= 1 and exist[:quantity] += 1
if add_on[:unit_amount_in_cents]
exist[:unit_amount_in_cents] = add_on[:unit_amount_in_cents]
end
else
@add_ons << add_on
end
@subscription[:subscription_add_ons] = to_a and self
end
|
#respond_to?(method_name, include_private = false) ⇒ Boolean
58
59
60
|
# File 'lib/recurly/subscription/add_ons.rb', line 58
def respond_to? method_name, include_private = false
super || @add_ons.respond_to?(method_name, include_private)
end
|
#to_a ⇒ Object
45
46
47
|
# File 'lib/recurly/subscription/add_ons.rb', line 45
def to_a
@add_ons.dup
end
|
#to_xml(options = {}) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/recurly/subscription/add_ons.rb', line 49
def to_xml options = {}
builder = options[:builder] || XML.new('<subscription_add_ons/>')
@add_ons.each do |add_on|
node = builder.add_element 'subscription_add_on'
add_on.each_pair { |k, v| node.add_element k.to_s, v }
end
builder.to_s
end
|