class FidorApi::Model::Base
Attributes
confirmable_action_id[RW]
Public Class Methods
inherited(klass)
click to toggle source
This makes define_method public to support Ruby lower than 2.5
# File lib/fidor_api/model/base.rb, line 8 def inherited(klass) klass.include ActiveModel::Model klass.include Helpers::ActionViewSupport klass.extend ModelAttribute klass.extend Helpers::AttributeDecimalMethods klass.define_method :initialize do |attributes = {}| set_attributes(attributes) end end
resource_name()
click to toggle source
# File lib/fidor_api/model/base.rb, line 20 def resource_name name.sub('FidorApi::Model::', '') end
Public Instance Methods
as_json()
click to toggle source
# File lib/fidor_api/model/base.rb, line 27 def as_json attributes.reject { |_, v| v.nil? } end
parse_errors(body)
click to toggle source
# File lib/fidor_api/model/base.rb, line 31 def parse_errors(body) # rubocop:disable Metrics/AbcSize Array(body['errors']).each do |hash| field = hash.delete('field').to_sym key = hash.delete('key') next unless respond_to?(field) || field == :base if key # https://github.com/rails/rails/issues/28903 errors.add(field, key.to_sym, hash.symbolize_keys.except(:message)) else errors.add(field, hash.delete('message'), hash.symbolize_keys) end end end