Sha256: af8786fa5af28af97b75696a7678647944d400d7d5563ff2b8afddeb35f7eb2b

Contents?: true

Size: 1.17 KB

Versions: 3

Compression:

Stored size: 1.17 KB

Contents

require 'cassandra_object/scope/batches'
require 'cassandra_object/scope/finder_methods'
require 'cassandra_object/scope/query_methods'

module CassandraObject
  class Scope
    include Batches, FinderMethods, QueryMethods

    attr_accessor :klass
    attr_accessor :limit_value, :select_values, :where_values, :id_values

    def initialize(klass)
      @klass = klass

      @limit_value    = nil
      @select_values  = []
      @where_values   = []
      @id_values      = []
    end

    private

      def scoping
        previous, klass.current_scope = klass.current_scope, self
        yield
      ensure
        klass.current_scope = previous
      end

      def method_missing(method_name, *args, &block)
        if klass.respond_to?(method_name)
          scoping { klass.send(method_name, *args, &block) }
        elsif Array.method_defined?(method_name)
          to_a.send(method_name, *args, &block)
        else
          super
        end
      end

      def select_records
        results = []
        klass.adapter.select(self) do |key, attributes|
          results << klass.instantiate(key, attributes)
        end
        results.compact!
        results
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.12.2 lib/cassandra_object/scope.rb
gotime-cassandra_object-4.12.1 lib/cassandra_object/scope.rb
gotime-cassandra_object-4.12.0 lib/cassandra_object/scope.rb