Class: Azeroth::Decorator::HashBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/azeroth/decorator/hash_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class responsible for building the hash on Decorator#as_json calls

Instance Method Summary collapse

Constructor Details

#initialize(decorator) ⇒ HashBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HashBuilder.

Parameters:

  • decorator (Decorator)

    decorator that will receive all method calls



14
15
16
# File 'lib/azeroth/decorator/hash_builder.rb', line 14

def initialize(decorator)
  @decorator = decorator
end

Instance Method Details

#as_jsonHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build hash as defined by decorator

The built of the hash keys is defined by decorator attributes and method calls to the same decorator that will then delgate, when needed, to its object

Returns:

  • (Hash)


26
27
28
29
30
31
32
33
# File 'lib/azeroth/decorator/hash_builder.rb', line 26

def as_json
  attributes_map.inject({}) do |hash, (method, options)|
    new_hash = KeyValueExtractor.new(
      decorator: decorator, attribute: method, options: options
    ).as_json
    hash.merge!(new_hash)
  end
end