class LocalModel::Collection
Attributes
add_to_collection[RW]
collection_class[RW]
model[RW]
Public Class Methods
create_from(array: , for_model: , for_collection_class:, add_to_collection_proc:)
click to toggle source
# File lib/local_model/collection.rb, line 3 def self.create_from(array: , for_model: , for_collection_class:, add_to_collection_proc:) new_obj = new(array) new_obj.model = for_model new_obj.collection_class = for_collection_class new_obj.add_to_collection = add_to_collection_proc new_obj end
Public Instance Methods
<<(arg)
click to toggle source
# File lib/local_model/collection.rb, line 13 def <<(arg) self.push(arg) end
build(arg)
click to toggle source
# File lib/local_model/collection.rb, line 24 def build(arg) self.push(arg) end
push(arg)
click to toggle source
# File lib/local_model/collection.rb, line 17 def push(arg) self.[]=(self.length, arg) raise ArgumentError.new("#{arg.class} inputted, expecting #{self.collection_class}") if !arg.is_a?(self.collection_class) add_to_collection[arg, self.model] arg.save && self.model.save end