Sha256: 06e874899be35571893c41e61c53352fcbe2d3184101e4c2ddfb8a91dba5b9aa

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

require 'api_resource/associations/scope'

module ApiResource
  
  module Associations
    
    class ResourceScope < Scope
      
      include Enumerable

      def internal_object
        ApiResource.with_ttl(ttl) do
          @internal_object ||= self.klass.send(:find, :all, :params => self.to_hash)
        end
      end
      
      alias_method :all, :internal_object
      
      def each(*args, &block)
        self.internal_object.each(*args, &block)
      end
      
      # get the relevant class
      def self.class_factory(hsh)
        case hsh.values.first
          when TrueClass, FalseClass
            ApiResource::Associations::ResourceScope
          when Array
            ApiResource::Associations::MultiArgumentResourceScope
          else
            ApiResource::Associations::DynamicResourceScope
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api_resource-0.3.14 lib/api_resource/associations/resource_scope.rb
api_resource-0.3.13 lib/api_resource/associations/resource_scope.rb