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.



22
23
24
# File 'lib/fidor_api/model/base.rb', line 22

def confirmable_action_id
  @confirmable_action_id
end

Class Method Details

.inherited(klass) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fidor_api/model/base.rb', line 5

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



17
18
19
# File 'lib/fidor_api/model/base.rb', line 17

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

Instance Method Details

#as_jsonObject



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

def as_json
  attributes.compact
end

#parse_errors(body) ⇒ Object

rubocop:disable Metrics/AbcSize



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fidor_api/model/base.rb', line 28

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
      errors.add(field, key.to_sym, hash.symbolize_keys)
    else
      errors.add(field, hash.delete('message'), hash.symbolize_keys)
    end
  end
end