Class: DB::Model::Scope

Inherits:
Relation show all
Defined in:
lib/db/model/scope.rb

Instance Attribute Summary collapse

Attributes inherited from Relation

#cache, #context, #model

Instance Method Summary collapse

Methods inherited from Relation

#create, #each, #find, #first, #inspect, #preload, #select, #to_a, #update_cache, #where

Methods included from Countable

#count, #empty?

Methods included from Deletable

#delete

Constructor Details

#initialize(context, model, attributes, cache = nil) ⇒ Scope

Returns a new instance of Scope.



28
29
30
31
32
# File 'lib/db/model/scope.rb', line 28

def initialize(context, model, attributes, cache = nil)
	super(context, model, cache)
	
	@attributes = attributes
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



34
35
36
# File 'lib/db/model/scope.rb', line 34

def attributes
  @attributes
end

Instance Method Details

#cache_keyObject



48
49
50
# File 'lib/db/model/scope.rb', line 48

def cache_key
	[@model, @attributes]
end

#insert(keys, rows, **attributes) ⇒ Object



40
41
42
# File 'lib/db/model/scope.rb', line 40

def insert(keys, rows, **attributes)
	@model.insert(@context, keys, rows, **@attributes.merge(attributes))
end

#new(**attributes) ⇒ Object



36
37
38
# File 'lib/db/model/scope.rb', line 36

def new(**attributes)
	@model.new(@context, {}, @cache).assign(**@attributes.merge(attributes))
end

#predicateObject



44
45
46
# File 'lib/db/model/scope.rb', line 44

def predicate
	Statement::Equal.new(@model, @attributes.keys, @attributes.values)
end

#to_sObject



52
53
54
# File 'lib/db/model/scope.rb', line 52

def to_s
	"\#<#{self.class} #{@model} #{@attributes}>"
end