Class: NormalizrRuby::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/normalizr_ruby/converter.rb

Defined Under Namespace

Classes: SchemaNotFound

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Converter

Returns a new instance of Converter.



5
6
7
8
9
# File 'lib/normalizr_ruby/converter.rb', line 5

def initialize(context)
  @context = context
  @entities = {}
  @result = nil
end

Instance Method Details

#normalize(resource, options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/normalizr_ruby/converter.rb', line 11

def normalize(resource, options)
  opts = options.presence || {}
  @result = walk(resource, opts)
  key_transform = NormalizrRuby.config.key_transform
  normalized_hash = { result: @result, entities: @entities }
  KeyTransform.send(key_transform, normalized_hash)
rescue SchemaNotFound => e
  resource
end