Method: Scimitar::Resources::Base#initialize

Defined in:
app/models/scimitar/resources/base.rb

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/scimitar/resources/base.rb', line 13

def initialize(options = {})
  flattened_attributes = flatten_extension_attributes(options)
  ci_all_attributes    = Scimitar::Support::HashWithIndifferentCaseInsensitiveAccess.new
  camel_attributes     = {}

  # Create a map where values are the schema-correct-case attribute names
  # and the values are set the same, but since the ci_all_attributes data
  # type is HashWithIndifferentCaseInsensitiveAccess, lookups in this are
  # case insensitive. Thus, arbitrary case input data can be mapped to
  # the case correctness required for ActiveModel's attribute accessors.
  #
  self.class.all_attributes.each { |attr| ci_all_attributes[attr] = attr }

  flattened_attributes.each do | key, value |
    if ci_all_attributes.key?(key)
      camel_attributes[ci_all_attributes[key]] = value
    end
  end

  super(camel_attributes)
  constantize_complex_types(camel_attributes)

  @errors = ActiveModel::Errors.new(self)
end