Sha256: 5af231b2cc75f4f1e43bcbbc8fc3bbbea478a45cbd178fe6aefe3c243782d092

Contents?: true

Size: 675 Bytes

Versions: 7

Compression:

Stored size: 675 Bytes

Contents

# frozen_string_literal: true

require 'grape_entity/delegator/base'
require 'grape_entity/delegator/hash_object'
require 'grape_entity/delegator/openstruct_object'
require 'grape_entity/delegator/fetchable_object'
require 'grape_entity/delegator/plain_object'

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

        delegator_klass.new(object)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
grape-entity-0.10.0 lib/grape_entity/delegator.rb
grape-entity-0.9.0 lib/grape_entity/delegator.rb
grape-entity-0.8.2 lib/grape_entity/delegator.rb
grape-entity-0.8.1 lib/grape_entity/delegator.rb
grape-entity-0.8.0 lib/grape_entity/delegator.rb
grape-entity-0.7.1 lib/grape_entity/delegator.rb
grape-entity-0.7.0 lib/grape_entity/delegator.rb