Sha256: 8e39c449555403446d77cbac2a825a44c6785045a907028075b136123bc9141b

Contents?: true

Size: 989 Bytes

Versions: 1

Compression:

Stored size: 989 Bytes

Contents

module DataMapper
  class Query
    attr_accessor :view, :view_options
  end
end

module DataMapper
  module CouchResource
    class View
      attr_reader :model, :name

      def initialize(model, name)
        @model = model
        @name = name

        create_getter
      end

      def create_getter
        @model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
          def self.#{@name}(*args)
            options = {}
            if args.size == 1 && !args.first.is_a?(Hash)
              options[:key] = args.shift
            else
              options = args.pop
            end
            query = Query.new(repository, self)
            query.view_options = options || {}
            query.view = '#{@name}'
            if options.is_a?(Hash) && options.has_key?(:repository)
              repository(options.delete(:repository)).read_many(query)
            else
              repository.read_many(query)
            end
          end
        RUBY
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-couchdb-adapter-0.10.2 lib/couchdb_adapter/view.rb