Sha256: 6f1d3c7b345136526c939bc56b0993ad913037214c5476c4e46791350aa23490
Contents?: true
Size: 1.32 KB
Versions: 14
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true require 'sinclair' module Azeroth class Decorator # @api private # # Class responsible for building the hash on # Decorator#as_json calls class HashBuilder # @param decorator [Decorator] decorator that # will receive all method calls def initialize(decorator) @decorator = decorator end # 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 # # @return [Hash] def as_json attributes_map.inject({}) do |hash, (method, options)| new_hash = KeyValueExtractor.new(decorator, method, options).as_json hash.merge!(new_hash) end end private attr_reader :decorator # @method decorator # @api private # @private # # decorator with object to be decorated # # @return [Decorator] # attributes to be built to hash # # The keys are the methods to be called and # the values are the exposing options # # @return [Hash] hash of pairs method,options def attributes_map decorator.class.attributes_map end end end end
Version data entries
14 entries across 14 versions & 1 rubygems