Module: Tupplur::ModelExtensions::InstanceMethods
- Defined in:
- lib/tupplur/model_extensions.rb
Instance Method Summary collapse
- #as_external_document ⇒ Object
- #external_update!(document_as_hash) ⇒ Object
-
#rest?(operation) ⇒ Boolean
Does the model allow a certain REST operation? If no operation given: Does the model allow any REST operation at all?.
Instance Method Details
#as_external_document ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tupplur/model_extensions.rb', line 17 def as_external_document doc = self.as_document # note: id fix for client side libraries like Spine.js, # who rely on an id attribute being present. doc['id'] = doc['_id'] doc.slice(*readable_fields + ['id']) end |
#external_update!(document_as_hash) ⇒ Object
27 28 29 30 |
# File 'lib/tupplur/model_extensions.rb', line 27 def external_update!(document_as_hash) allowed_fields = filter_accessible_fields(document_as_hash) update_attributes!(allowed_fields) end |
#rest?(operation) ⇒ Boolean
Does the model allow a certain REST operation? If no operation given: Does the model allow any REST operation at all?
34 35 36 37 38 39 40 |
# File 'lib/tupplur/model_extensions.rb', line 34 def rest?(operation) if operation self.class.const_get(:REST_INTERFACE).include?(operation) else ! self.class.const_get(:REST_INTERFACE).empty? end end |