Module: Grape::Entity::Delegator

Defined in:
lib/grape_entity/delegator.rb,
lib/grape_entity/delegator/base.rb,
lib/grape_entity/delegator/hash_object.rb,
lib/grape_entity/delegator/plain_object.rb,
lib/grape_entity/delegator/fetchable_object.rb,
lib/grape_entity/delegator/openstruct_object.rb

Defined Under Namespace

Classes: Base, FetchableObject, HashObject, OpenStructObject, PlainObject

Class Method Summary collapse

Class Method Details

.new(object) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grape_entity/delegator.rb', line 12

def self.new(object)
  delegator_klass =
    if object.is_a?(Hash)
      HashObject
    elsif defined?(OpenStruct) && object.is_a?(OpenStruct)
      OpenStructObject
    elsif object.respond_to?(:fetch, true)
      FetchableObject
    else
      PlainObject
    end

  delegator_klass.new(object)
end