Class: ActiveCic::Base
- Inherits:
-
Object
- Object
- ActiveCic::Base
- Includes:
- HTTParty
- Defined in:
- lib/cic/active_cic.rb
Direct Known Subclasses
Constant Summary collapse
- BASE_URL =
"api.nl.cic.mx/0/nl"
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#raw_attributes ⇒ Object
readonly
Returns the value of attribute raw_attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Base
constructor
A new instance of Base.
- #method_missing(name, *args) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Base
Returns a new instance of Base.
17 18 19 20 |
# File 'lib/cic/active_cic.rb', line 17 def initialize(hash) self.attributes = Hashie::Mash.new(hash) @raw_attributes = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
22 23 24 25 26 |
# File 'lib/cic/active_cic.rb', line 22 def method_missing(name, *args) self.attributes.send(name, args) rescue NoMethodError super end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/cic/active_cic.rb', line 8 def attributes @attributes end |
#raw_attributes ⇒ Object (readonly)
Returns the value of attribute raw_attributes.
9 10 11 |
# File 'lib/cic/active_cic.rb', line 9 def raw_attributes @raw_attributes end |
Class Method Details
.all ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/cic/active_cic.rb', line 28 def self.all class_name = self.pluralize_child_class_name response = self.get("/#{class_name}.json") if response.success? response.parsed_response[class_name].map { |hash| self.new(hash) } else raise_exception(response.code, response.body) end end |