module Tupplur::ModelExtensions::InstanceMethods

Public Instance Methods

as_external_document() click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Does the model allow a certain REST operation? If no operation given: Does the model allow any REST operation at all?

# 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

Private Instance Methods

filter_accessible_fields(hsh) click to toggle source
# File lib/tupplur/model_extensions.rb, line 44
def filter_accessible_fields(hsh)
  hsh.slice(*self.class.const_get(:EXTERNALLY_ACCESSIBLE_FIELDS).map(&:to_s))
end
readable_fields() click to toggle source
# File lib/tupplur/model_extensions.rb, line 48
def readable_fields
  (self.class.const_get(:EXTERNALLY_ACCESSIBLE_FIELDS) + self.class.const_get(:EXTERNALLY_READABLE_FIELDS)).map(&:to_s)
end