Class: AmemberPro::Parameters
- Inherits:
-
Object
- Object
- AmemberPro::Parameters
- Defined in:
- lib/amember_pro/parameters.rb
Defined Under Namespace
Classes: Nested
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#key ⇒ Object
Returns the value of attribute key.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(&block) ⇒ Parameters
constructor
A new instance of Parameters.
- #method_missing(method, *args) ⇒ Object
- #nested(nest) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #underscore_prefix ⇒ Object
Constructor Details
#initialize(&block) ⇒ Parameters
Returns a new instance of Parameters.
45 46 47 48 |
# File 'lib/amember_pro/parameters.rb', line 45 def initialize &block self.parameters = Hash.new self.instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/amember_pro/parameters.rb', line 8 def method_missing method, *args self.args = args self.key = method.to_s self.value = self.args[0] case method when :format underscore_prefix self.value ||= 'json' when :count underscore_prefix self.value ||= '20' when :page underscore_prefix self.value ||= '0' when :filter underscore_prefix filterify end add self.key.to_s, self.value.to_s end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/amember_pro/parameters.rb', line 6 def args @args end |
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/amember_pro/parameters.rb', line 4 def key @key end |
#parameters ⇒ Object
Returns the value of attribute parameters.
3 4 5 |
# File 'lib/amember_pro/parameters.rb', line 3 def parameters @parameters end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/amember_pro/parameters.rb', line 5 def value @value end |
Instance Method Details
#add(key, value) ⇒ Object
50 51 52 53 |
# File 'lib/amember_pro/parameters.rb', line 50 def add key, value self.parameters[key.to_s] = value.to_s self.parameters end |
#delete(key) ⇒ Object
30 31 32 |
# File 'lib/amember_pro/parameters.rb', line 30 def delete key self.parameters.to_hash.delete(key.to_s) end |
#nested(nest) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/amember_pro/parameters.rb', line 34 def nested nest unless nest.is_a? AmemberPro::Parameters::Nested raise "Nest must be of type AmemberPro::Parameters::Nested" end self.parameters.merge!(nest.to_hash) end |
#to_hash ⇒ Object
55 56 57 |
# File 'lib/amember_pro/parameters.rb', line 55 def to_hash self.to_s end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/amember_pro/parameters.rb', line 59 def to_s current_params end |
#underscore_prefix ⇒ Object
41 42 43 |
# File 'lib/amember_pro/parameters.rb', line 41 def underscore_prefix self.key = self.key.insert(0, '_') end |