Module: Her::Model::ORM::SaveMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Her::Model::ORM
- Defined in:
- lib/her/model/orm/save_methods.rb
Instance Method Summary collapse
- #create_or_update ⇒ Object
-
#save ⇒ Object
Save a resource.
- #save! ⇒ Object
Instance Method Details
#create_or_update ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/her/model/orm/save_methods.rb', line 31 def create_or_update params = to_params resource = self if @data[:id] hooks = [:update, :save] method = :put else hooks = [:create, :save] method = :post end self.class.wrap_in_hooks(resource, *hooks) do |resource, klass| klass.request(params.merge(_method: method, _path: request_path)) do |parsed_data| self.data = self.class.parse(parsed_data[:data]) if parsed_data[:data].any? self. = parsed_data[:metadata] self.errors = parsed_data[:errors] return false if self.errors.any? end end self end |
#save ⇒ Object
Save a resource
20 21 22 |
# File 'lib/her/model/orm/save_methods.rb', line 20 def save create_or_update end |
#save! ⇒ Object
24 25 26 27 28 29 |
# File 'lib/her/model/orm/save_methods.rb', line 24 def save! save raise RecordInvalid.new(self.errors) unless self.errors.empty? self end |