Class: Fill::Procedure
- Inherits:
-
Object
- Object
- Fill::Procedure
- Defined in:
- lib/fill/procedure.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #count ⇒ Object
- #delete_all ⇒ Object
- #human_models ⇒ Object
- #humanize_models ⇒ Object
- #i18n_name(model) ⇒ Object
-
#initialize(models, options = {}, &block) ⇒ Procedure
constructor
A new instance of Procedure.
- #models ⇒ Object
- #perform ⇒ Object
- #perform! ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(models, options = {}, &block) ⇒ Procedure
Returns a new instance of Procedure.
7 8 9 10 11 |
# File 'lib/fill/procedure.rb', line 7 def initialize(models, = {}, &block) @block = block @options = { :delete => true }.merge() @models = models end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/fill/procedure.rb', line 5 def block @block end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/fill/procedure.rb', line 5 def @options end |
Instance Method Details
#count ⇒ Object
41 42 43 |
# File 'lib/fill/procedure.rb', line 41 def count models.map { |model| model.count } end |
#delete_all ⇒ Object
33 34 35 |
# File 'lib/fill/procedure.rb', line 33 def delete_all models.map { |model| model.delete_all } end |
#human_models ⇒ Object
21 22 23 |
# File 'lib/fill/procedure.rb', line 21 def human_models @human_models ||= ([:name] || humanize_models) end |
#humanize_models ⇒ Object
25 26 27 |
# File 'lib/fill/procedure.rb', line 25 def humanize_models models.map { |model| i18n_name(model) }.join(', ') end |
#i18n_name(model) ⇒ Object
29 30 31 |
# File 'lib/fill/procedure.rb', line 29 def i18n_name(model) model.respond_to?(:human_name) ? model.human_name : model.to_s end |
#models ⇒ Object
37 38 39 |
# File 'lib/fill/procedure.rb', line 37 def models @models.map { |model| model.to_s.singularize.camelize.constantize } end |
#perform ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/fill/procedure.rb', line 45 def perform @before = [:delete] ? delete_all : count @time = Fill.time { block.call } @after = count Presenter.present self true end |
#perform! ⇒ Object
13 14 15 |
# File 'lib/fill/procedure.rb', line 13 def perform! @performed ||= perform end |
#to_hash ⇒ Object
17 18 19 |
# File 'lib/fill/procedure.rb', line 17 def to_hash { "Models" => human_models, "Before" => @before.join(', '), "After" => @after.join(', '), "Time" => @time } end |