class Treant
Public Class Methods
new(model, *unique_keys)
click to toggle source
# File lib/treant.rb, line 4 def initialize(model, *unique_keys) @model = model @unique_keys = unique_keys end
Public Instance Methods
seed() { |attrs| ... }
click to toggle source
# File lib/treant.rb, line 9 def seed attrs = OpenStruct.new yield(attrs) conditions = @unique_keys.each_with_object({}) { |k, h| h[k] = attrs[k] } record = @model.find_or_initialize_by(conditions) record.update!(attrs.to_h) record end