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.



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

#attributesObject (readonly)

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_keyObject



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

#predicateObject



27
28
29
# File 'lib/db/model/scope.rb', line 27

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

#to_sObject



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

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