Sha256: 8f5f0f48762c6f56655e09a7ce58e3bc05bde7526bbc861ce499d976c1a217cf

Contents?: true

Size: 640 Bytes

Versions: 10

Compression:

Stored size: 640 Bytes

Contents

module ApiClient

  module Mixins

    module Instantiation

      def self.extended(base)
        base.instance_eval do
          attr_accessor :original_scope
        end
      end

      def build_one(hash)
        instance = self.new self.namespace ? hash[namespace] : hash
        instance.original_scope = self.scope
        instance
      end

      def build_many(array)
        array.collect { |one| build_one(one) }
      end

      def build(result_or_array)
        if result_or_array.is_a?(Array)
          build_many result_or_array
        else
          build_one  result_or_array
        end
      end

    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
api_client-0.1.9 lib/api_client/mixins/instantiation.rb
api_client-0.1.8 lib/api_client/mixins/instantiation.rb
api_client-0.1.7 lib/api_client/mixins/instantiation.rb
api_client-0.1.6 lib/api_client/mixins/instantiation.rb
api_client-0.1.5 lib/api_client/mixins/instantiation.rb
api_client-0.1.4 lib/api_client/mixins/instantiation.rb
api_client-0.1.3 lib/api_client/mixins/instantiation.rb
api_client-0.1.2 lib/api_client/mixins/instantiation.rb
api_client-0.1.1 lib/api_client/mixins/instantiation.rb
api_client-0.1.0 lib/api_client/mixins/instantiation.rb