Class: AmemberPro::Parameters::Nested
- Inherits:
-
Object
- Object
- AmemberPro::Parameters::Nested
- Defined in:
- lib/amember_pro/parameters.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#nest ⇒ Object
Returns the value of attribute nest.
-
#nested ⇒ Object
Returns the value of attribute nested.
Instance Method Summary collapse
- #<<(params) ⇒ Object
-
#initialize(nest, &block) ⇒ Nested
constructor
A new instance of Nested.
- #nestify ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(nest, &block) ⇒ Nested
81 82 83 84 85 86 |
# File 'lib/amember_pro/parameters.rb', line 81 def initialize nest, &block self.nest = nest.to_s self.args = [] self.instance_eval(&block) if block_given? nestify end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
78 79 80 |
# File 'lib/amember_pro/parameters.rb', line 78 def args @args end |
#nest ⇒ Object
Returns the value of attribute nest.
77 78 79 |
# File 'lib/amember_pro/parameters.rb', line 77 def nest @nest end |
#nested ⇒ Object
Returns the value of attribute nested.
79 80 81 |
# File 'lib/amember_pro/parameters.rb', line 79 def nested @nested end |
Instance Method Details
#<<(params) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/amember_pro/parameters.rb', line 88 def << params unless params.is_a? AmemberPro::Parameters raise "params must be of type AmemberPro::Parameters" end self.args << params.to_hash end |
#nestify ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/amember_pro/parameters.rb', line 103 def nestify self.nested = Hash.new unless self.args.empty? self.args.each_with_index do |arg, index| n = "nested[#{self.nest}][#{index}]" arg.each do |key,val| k = "#{n}[#{key}]" self.nested[k] = val end end else self.nested["_nested[]"] = self.nest end end |
#to_hash ⇒ Object
95 96 97 |
# File 'lib/amember_pro/parameters.rb', line 95 def to_hash self.to_s end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/amember_pro/parameters.rb', line 99 def to_s self.nested end |