Module: JSONAPIonify::Api::Resource::Defaults::Hooks

Extended by:
ActiveSupport::Concern
Defined in:
lib/jsonapionify/api/resource/defaults/hooks.rb

Instance Method Summary collapse

Instance Method Details

#commit_active_record(instance) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/jsonapionify/api/resource/defaults/hooks.rb', line 57

def commit_active_record(instance)
  instance.save
  if instance.errors.present?
    instance.errors.messages.each do |attr, messages|
      messages.each do |message|
        error :invalid_attribute, attr, message
      end
    end
  end
end

#try_commit(instance) ⇒ Object



51
52
53
54
55
# File 'lib/jsonapionify/api/resource/defaults/hooks.rb', line 51

def try_commit(instance)
  if defined?(ActiveRecord) && instance.is_a?(ActiveRecord::Base)
    commit_active_record(instance)
  end
end