module GlobalRegistryModels::APIOperations::Persistence::ClassMethods
Public Instance Methods
create(attributes)
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 33 def create(attributes) create! attributes rescue GlobalRegistryModels::RecordInvalid false end
create!(attributes)
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 19 def create!(attributes) object = new(attributes.with_indifferent_access.except(:id)) if object.valid? create_attributes = prepare_parameters(object, attributes) response = global_registry_resource.post(attributes_hash(create_attributes)) if response.present? response_hash = response[ressource_type] response_hash.has_key?(name) ? (new response_hash[name]) : (new response_hash) end else raise GlobalRegistryModels::RecordInvalid.new end end
prepare_parameters(object, attributes)
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 8 def prepare_parameters(object, attributes) attribute_keys = attributes.keys.collect(&:to_sym) & writeable_attributes prepared_attributes = object.attributes.with_indifferent_access.slice(*attribute_keys) prepared_attributes = specific_attributes_preparations(object, prepared_attributes) prepared_attributes end
ressource_type()
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 15 def ressource_type global_registry_resource.to_s.demodulize.underscore end
update(id, attributes)
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 50 def update(id, attributes) update! id, attributes rescue GlobalRegistryModels::RecordInvalid false end
update!(id, attributes)
click to toggle source
# File lib/global_registry_models/api_operations/persistence.rb, line 39 def update!(id, attributes) object = new(attributes) if object.valid? update_attributes = prepare_parameters(object, attributes) response_hash = global_registry_resource.put(id, attributes_hash(update_attributes))[ressource_type] response_hash.has_key?(name) ? (new response_hash[name]) : (new response_hash) else raise GlobalRegistryModels::RecordInvalid.new end end