Sha256: ad7d2e0a98a503d5d1fc2e86bd143b8106f63eb0ebb200190859ad567b4ab913

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

module ApiResource
  module Associations
    class Scope < AbstractScope

      def initialize(klass, opts = {})
        # see if we have a hash of options and it has a parent in it
        unless opts[:__parent].respond_to?(:load)
          raise ArgumentError.new(
            "Scopes must have a parent object passed in that " + 
            "responds to #load"
          )
        end
        super(klass, opts)
      end

      def load
        ret = self.klass.load(self.to_hash)
        @loaded = true
        ret
      end

      # we break this out here because Scope needs to pass self.klass to 
      # any sub-scopes.  This is because Scope does not have knowledge
      # of how to actually load data and delegates that to either
      # a ResourceScope or an AssociationScope
      def get_subscope_instance(finder_opts)
        ApiResource::Associations::Scope.new(
          self.klass, finder_opts.merge(:__parent => self)
        )
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api_resource-0.5.1 lib/api_resource/associations/scope.rb
api_resource-0.5.0 lib/api_resource/associations/scope.rb