Class: UpdateAllScope
- Inherits:
-
Object
- Object
- UpdateAllScope
- Defined in:
- lib/atomically/update_all_scope.rb
Instance Method Summary collapse
- #do_query! ⇒ Object
-
#initialize(model: nil, relation: nil) ⇒ UpdateAllScope
constructor
A new instance of UpdateAllScope.
- #klass ⇒ Object
- #update(query, *binding_values) ⇒ Object
- #where(*args) ⇒ Object
Constructor Details
#initialize(model: nil, relation: nil) ⇒ UpdateAllScope
Returns a new instance of UpdateAllScope.
4 5 6 7 |
# File 'lib/atomically/update_all_scope.rb', line 4 def initialize(model: nil, relation: nil) @queries = [] @relation = relation || model.class.where(id: model.id) end |
Instance Method Details
#do_query! ⇒ Object
20 21 22 23 |
# File 'lib/atomically/update_all_scope.rb', line 20 def do_query! return 0 if @queries.empty? return @relation.update_all(@queries.join(',')) end |
#klass ⇒ Object
25 26 27 |
# File 'lib/atomically/update_all_scope.rb', line 25 def klass @relation.klass end |
#update(query, *binding_values) ⇒ Object
14 15 16 17 18 |
# File 'lib/atomically/update_all_scope.rb', line 14 def update(query, *binding_values) args = binding_values.size > 0 ? [[query, *binding_values]] : [query] @queries << klass.send(:sanitize_sql_for_assignment, *args) return self end |
#where(*args) ⇒ Object
9 10 11 12 |
# File 'lib/atomically/update_all_scope.rb', line 9 def where(*args) @relation = @relation.where(*args) return self end |