Module: Ahub::APIResource
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ahub/modules/api_resource.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #initialize(attrs) ⇒ Object
- #json_url ⇒ Object
- #update ⇒ Object
- #update_attribute(attribute, value) ⇒ Object
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/ahub/modules/api_resource.rb', line 9 def attributes @attributes end |
Instance Method Details
#initialize(attrs) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ahub/modules/api_resource.rb', line 11 def initialize(attrs) @attributes ||= {} attrs.each_pair { |k,v| @attributes[k.to_sym] = v } attrs.each_pair do |k,v| attribute_name = k.to_s.underscore if instance_variable_get("@#{attribute_name}").nil? instance_variable_set("@#{attribute_name}", v) end next if respond_to?(k) && k != :id self.class.send(:define_method, attribute_name) do instance_variable_get("@#{__method__}") end end end |
#json_url ⇒ Object
30 31 32 |
# File 'lib/ahub/modules/api_resource.rb', line 30 def json_url "#{self.class.base_url}/#{id}.json" if id end |
#update ⇒ Object
34 35 36 |
# File 'lib/ahub/modules/api_resource.rb', line 34 def update raise NotImplementedError end |
#update_attribute(attribute, value) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/ahub/modules/api_resource.rb', line 38 def update_attribute(attribute, value) payload = {} payload[attribute] = value self.class.update_resource(resource: self, payload: payload) end |