Module: LinkedData::Client::ReadWrite
- Included in:
- Models::Mapping, Models::Note, Models::Ontology, Models::OntologySubmission, Models::Project, Models::Reply, Models::Review, Models::User
- Defined in:
- lib/ontologies_api_client/read_write.rb
Constant Summary collapse
- HTTP =
LinkedData::Client::HTTP
Instance Method Summary collapse
- #changed_values ⇒ Object
- #delete ⇒ Object
- #save ⇒ Object
- #update(options = {}) ⇒ Object
- #update_from_params(params) ⇒ Object
Instance Method Details
#changed_values ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ontologies_api_client/read_write.rb', line 38 def changed_values existing = HTTP.get(self.id, include: "all") changed_attrs = {} self.instance_variables.each do |var| var_sym = var[1..-1].to_sym next if [:id, :type, :links, :context, :created].include?(var_sym) new_value = self.instance_variable_get(var) current_value = existing.instance_variable_get(var) changed_attrs[var_sym] = new_value unless equivalent?(current_value, new_value) end changed_attrs end |
#delete ⇒ Object
51 52 53 54 55 |
# File 'lib/ontologies_api_client/read_write.rb', line 51 def delete resp = HTTP.delete(self.id) invalidate_cache() resp end |
#save ⇒ Object
8 9 10 11 12 |
# File 'lib/ontologies_api_client/read_write.rb', line 8 def save resp = HTTP.post(self.class.collection_path, self.to_hash) invalidate_cache() resp end |
#update(options = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/ontologies_api_client/read_write.rb', line 14 def update( = {}) values = [:values] || changed_values() return if values.empty? resp = HTTP.patch(self.id, values) invalidate_cache() resp end |
#update_from_params(params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ontologies_api_client/read_write.rb', line 22 def update_from_params(params) # We want to populate ALL the attributes from the REST # service so we know that what we're updating is # actually the full object all_values = HTTP.get(self.id, include: "all") all_values.instance_variables.each do |var| self.send("#{var}=", all_values.instance_variable_get(var)) end # Now we override the retrieved attributes with new ones params.each do |k,v| self.send("#{k}=", v) rescue next end self end |