Class: Cuttings::Greenhouse

Inherits:
Object
  • Object
show all
Defined in:
lib/cuttings/greenhouse.rb

Instance Method Summary collapse

Instance Method Details

#creatable_modelsObject



16
17
18
# File 'lib/cuttings/greenhouse.rb', line 16

def creatable_models
  @creatable_models ||= []
end

#processObject



20
21
22
23
# File 'lib/cuttings/greenhouse.rb', line 20

def process
  truncate_models
  creatable_models.each(&:run)
end

#seed(model_name, options = {}, &block) ⇒ Object



3
4
5
6
# File 'lib/cuttings/greenhouse.rb', line 3

def seed(model_name, options = {}, &block)
  truncatable_models << model_name unless options.delete(:truncate) == false
  creatable_models << Cutting.new(model_name, options, &block)
end

#truncatable_modelsObject



12
13
14
# File 'lib/cuttings/greenhouse.rb', line 12

def truncatable_models
  @truncatable_models ||= []
end

#truncate(*model_names) ⇒ Object



8
9
10
# File 'lib/cuttings/greenhouse.rb', line 8

def truncate(*model_names)
  truncatable_models.concat(model_names.flatten)
end

#truncate_modelsObject



25
26
27
28
29
# File 'lib/cuttings/greenhouse.rb', line 25

def truncate_models
  truncatable_models.each do |model_name|
    model_name.constantize.destroy_all
  end
end