Class: ActsAsTable::RecordModelClassMethods::FindOrInitializeBy
- Inherits:
-
Object
- Object
- ActsAsTable::RecordModelClassMethods::FindOrInitializeBy
- Defined in:
- app/models/concerns/acts_as_table/record_model_class_methods.rb
Overview
ActsAsTable "destructive" traversal (creates new records if they are not found and updates persisted records).
Instance Method Summary collapse
-
#arity ⇒ Integer
Returns the number of mandatory arguments.
-
#call(record_model, base = nil) ⇒ ActsAsTable::ValueProvider::WrappedValue
Invokes the traversal.
-
#inject(acc, record_model, base = nil) {|acc, path| ... } ⇒ Object
Combine all ActsAsTable paths using an associative binary operation.
Instance Method Details
#arity ⇒ Integer
Returns the number of mandatory arguments.
159 160 161 |
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 159 def arity 1 end |
#call(record_model, base = nil) ⇒ ActsAsTable::ValueProvider::WrappedValue
Invokes the traversal.
169 170 171 |
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 169 def call(record_model, base = nil) raise ::NotImplementedError.new("#{self.class}#call") end |
#inject(acc, record_model, base = nil) {|acc, path| ... } ⇒ Object
Combine all ActsAsTable paths using an associative binary operation.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'app/models/concerns/acts_as_table/record_model_class_methods.rb', line 183 def inject(acc, record_model, base = nil) # @return [Class] klass = record_model.class_name.constantize # @return [ActsAsTable::Path] path = ActsAsTable::Path.new(klass, nil, data: { source_record_model: nil, source_record: nil, target_record_model: record_model, target_record: base, }) _inject(acc, path, **{ find_or_initialize_by: ::Proc.new { |*args, &block| ActsAsTable.adapter.find_or_initialize_by_for(record_model, klass, :find_by!, *args, &block) }, new: ::Proc.new { |*args, &block| ActsAsTable.adapter.new_for(record_model, klass, :new, *args, &block) }, }) end |