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
# File 'lib/grape_entity/delegator.rb', line 12

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