Class: State
- Inherits:
-
Object
- Object
- State
- Defined in:
- lib/core.rb
Overview
CORE: State of the system It should hold all the information we need to build the system, packages, files, changes…etc. everything will run inside an instance of this class
Instance Method Summary collapse
- #apply(block) ⇒ Object
-
#on_configure(id = nil, &block) ⇒ Object
Same as on_prepare but for configure step.
-
#on_finalize(id = nil, &block) ⇒ Object
Same as on_finalize but for configure step.
-
#on_install(id = nil, &block) ⇒ Object
Same as on_prepare but for install step.
-
#on_prepare(id = nil, &block) ⇒ Object
Run block on prepare step.
-
#run_steps ⇒ Object
Run all registered code blocks in the following order: Prepare, Install, Configure, Finalize.
Instance Method Details
#apply(block) ⇒ Object
8 9 10 |
# File 'lib/core.rb', line 8 def apply(block) instance_eval &block end |
#on_configure(id = nil, &block) ⇒ Object
Same as on_prepare but for configure step
29 30 31 32 33 |
# File 'lib/core.rb', line 29 def on_configure(id=nil, &block) id ||= caller_locations(1,1).first.to_s @configure_steps ||= {} @configure_steps[id] = block end |
#on_finalize(id = nil, &block) ⇒ Object
Same as on_finalize but for configure step
36 37 38 39 40 |
# File 'lib/core.rb', line 36 def on_finalize(id=nil, &block) id ||= caller_locations(1,1).first.to_s @finalize_steps ||= {} @finalize_steps[id] = block end |
#on_install(id = nil, &block) ⇒ Object
Same as on_prepare but for install step
22 23 24 25 26 |
# File 'lib/core.rb', line 22 def on_install(id=nil, &block) id ||= caller_locations(1,1).first.to_s @install_steps ||= {} @install_steps[id] = block end |
#on_prepare(id = nil, &block) ⇒ Object
Run block on prepare step. id identifies the block uniqueness in the steps. registering a block with same id multiple times replaces old block by new one. if id is nil the block location in source code is used as an id
15 16 17 18 19 |
# File 'lib/core.rb', line 15 def on_prepare(id=nil, &block) id ||= caller_locations(1,1).first.to_s @prepare_steps ||= {} @prepare_steps[id] = block end |
#run_steps ⇒ Object
Run all registered code blocks in the following order: Prepare, Install, Configure, Finalize
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/core.rb', line 43 def run_steps if @prepare_steps&.any? log "=> Prepare" @prepare_steps.each { |_, step| apply(step) } end if @install_steps&.any? log "=> Install" @install_steps.each { |_, step| apply(step) } end if @configure_steps&.any? log "=> Configure" @configure_steps.each { |_, step| apply(step) } end if @finalize_steps&.any? log "=> Finalize" @finalize_steps.each { |_, step| apply(step) } end end |