Module: JSONAPI::Consumer::Resource::AttributesConcern
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::AttributeMethods, ActiveModel::Dirty
- Included in:
- JSONAPI::Consumer::Resource
- Defined in:
- lib/jsonapi/consumer/resource/attributes_concern.rb
Instance Method Summary collapse
- #attributes=(attrs = {}) ⇒ Object
- #persisted? ⇒ Boolean
- #respond_to?(method, include_private_methods = false) ⇒ Boolean
-
#respond_to_without_attributes? ⇒ Object
end.
- #to_param ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#attributes=(attrs = {}) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 12 def attributes=(attrs={}) @attributes ||= {} return @attributes unless attrs.present? attrs.each do |key, value| set_attribute(key, value) end end |
#persisted? ⇒ Boolean
26 27 28 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 26 def persisted? !self.to_param.blank? end |
#respond_to?(method, include_private_methods = false) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 43 def respond_to?(method, include_private_methods=false) if super true elsif !include_private_methods && super(method, true) # If we're here then we haven't found among non-private methods # but found among all methods. Which means that the given method is private. false else has_attribute?(method) end end |
#respond_to_without_attributes? ⇒ Object
end
42 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 42 alias :respond_to_without_attributes? :respond_to? |
#to_param ⇒ Object
30 31 32 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 30 def to_param attributes.fetch(primary_key, '').to_s end |
#update_attributes(attrs = {}) ⇒ Object
21 22 23 24 |
# File 'lib/jsonapi/consumer/resource/attributes_concern.rb', line 21 def update_attributes(attrs={}) self.attributes = attrs # FIXME save end |