Module: HasLifecycle::ClassMethods
- Defined in:
- lib/geoengineer/utils/has_lifecycle.rb
Overview
ClassMethods
Instance Method Summary collapse
- #_init_validation_hash ⇒ Object
-
#after(lifecycle_step, method_name_or_proc) ⇒ Object
Currently only supporting after(:initialize).
- #before(lifecycle_step, method_name_or_proc) ⇒ Object
- #lifecycle_actions(stage, step) ⇒ Object
Instance Method Details
#_init_validation_hash ⇒ Object
11 12 13 14 15 16 |
# File 'lib/geoengineer/utils/has_lifecycle.rb', line 11 def _init_validation_hash { after: {}, before: {} } end |
#after(lifecycle_step, method_name_or_proc) ⇒ Object
Currently only supporting after(:initialize)
31 32 33 34 35 |
# File 'lib/geoengineer/utils/has_lifecycle.rb', line 31 def after(lifecycle_step, method_name_or_proc) @_actions = _init_validation_hash unless @_actions @_actions[:after][lifecycle_step] = [] unless @_actions[:after][lifecycle_step] @_actions[:after][lifecycle_step] << method_name_or_proc end |
#before(lifecycle_step, method_name_or_proc) ⇒ Object
37 38 39 40 41 |
# File 'lib/geoengineer/utils/has_lifecycle.rb', line 37 def before(lifecycle_step, method_name_or_proc) @_actions = _init_validation_hash unless @_actions @_actions[:before][lifecycle_step] = [] unless @_actions[:before][lifecycle_step] @_actions[:before][lifecycle_step] << method_name_or_proc end |
#lifecycle_actions(stage, step) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/geoengineer/utils/has_lifecycle.rb', line 18 def lifecycle_actions(stage, step) all = [] # inherit lifecycle_actions sclazz = self.superclass all.concat(sclazz.lifecycle_actions(stage, step)) if sclazz.respond_to?(:lifecycle_actions) # Add this lifecycle actions la_exists = @_actions && @_actions[stage] && @_actions[stage][step] all.concat(@_actions[stage][step]) if la_exists all end |