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.
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
#attributes ⇒ Object
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_key ⇒ Object
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
|
#predicate ⇒ Object
44
45
46
|
# File 'lib/db/model/scope.rb', line 44
def predicate
Statement::Equal.new(@model, @attributes.keys, @attributes.values)
end
|
#to_s ⇒ Object
52
53
54
|
# File 'lib/db/model/scope.rb', line 52
def to_s
"\#<#{self.class} #{@model} #{@attributes}>"
end
|