Class: FidorApi::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fidor_api/model/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#confirmable_action_idObject

Returns the value of attribute confirmable_action_id.



25
26
27
# File 'lib/fidor_api/model/base.rb', line 25

def confirmable_action_id
  @confirmable_action_id
end

Class Method Details

.inherited(klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# 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_nameObject



20
21
22
# File 'lib/fidor_api/model/base.rb', line 20

def resource_name
  name.sub('FidorApi::Model::', '')
end

Instance Method Details

#as_jsonObject



27
28
29
# File 'lib/fidor_api/model/base.rb', line 27

def as_json
  attributes.reject { |_, v| v.nil? }
end

#parse_errors(body) ⇒ Object

rubocop:disable Metrics/AbcSize



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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