Class: DB::Model::Scope
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.
11
12
13
14
15
|
# File 'lib/db/model/scope.rb', line 11
def initialize(context, model, attributes, cache = nil)
super(context, model, cache)
@attributes = attributes
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
17
18
19
|
# File 'lib/db/model/scope.rb', line 17
def attributes
@attributes
end
|
Instance Method Details
#cache_key ⇒ Object
31
32
33
|
# File 'lib/db/model/scope.rb', line 31
def cache_key
[@model, @attributes]
end
|
#insert(keys, rows, **attributes) ⇒ Object
23
24
25
|
# File 'lib/db/model/scope.rb', line 23
def insert(keys, rows, **attributes)
@model.insert(@context, keys, rows, **@attributes.merge(attributes))
end
|
#new(**attributes) ⇒ Object
19
20
21
|
# File 'lib/db/model/scope.rb', line 19
def new(**attributes)
@model.new(@context, {}, @cache).assign(**@attributes.merge(attributes))
end
|
#predicate ⇒ Object
27
28
29
|
# File 'lib/db/model/scope.rb', line 27
def predicate
Statement::Equal.new(@model, @attributes.keys, @attributes.values)
end
|
#to_s ⇒ Object
35
36
37
|
# File 'lib/db/model/scope.rb', line 35
def to_s
"\#<#{self.class} #{@model} #{@attributes}>"
end
|