Module: GeneSystem::Commands::Helpers
- Included in:
- InstallManifest, RemoveManifest
- Defined in:
- lib/gene_system/commands/helpers.rb
Overview
Install/Remove shared helper functions
Instance Method Summary collapse
-
#ask(prompts = []) ⇒ Object
Asks for user input when given prompts.
-
#filters ⇒ Hash
Constructs a filter function hash.
-
#filters? ⇒ Boolean
Returns true when an inclusion filter and/or an exclusion filter is specified in command options.
-
#skip?(direction, step, platform) ⇒ Boolean
Determines whether to skip a step.
-
#steps ⇒ GeneSystem::StepCollection
Returns manifest steps that match command options.
Instance Method Details
#ask(prompts = []) ⇒ Object
Asks for user input when given prompts
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gene_system/commands/helpers.rb', line 12 def ask(prompts = []) answers = @manifest.variables return answers if prompts.nil? || prompts.empty? prompts.each do |prompt| resp = @prompt.ask(prompt.prompt) answers[prompt.var] = resp end answers end |
#filters ⇒ Hash
Constructs a filter function hash
The key of the hash is the filter function and the value is the tags to filter by
If no inclusions or exclusions are specified then an empty hash is returned
76 77 78 79 80 81 82 83 84 |
# File 'lib/gene_system/commands/helpers.rb', line 76 def filters filters = {} filters[StepCollection::STEP_INCLUDE_ANY_TAG] = @options. if @options. filters[StepCollection::STEP_EXCLUDE_ANY_TAG] = @options. if @options. filters end |
#filters? ⇒ Boolean
Returns true when an inclusion filter and/or an exclusion filter is specified in command options.
Otherwise it returns false
95 96 97 98 99 100 |
# File 'lib/gene_system/commands/helpers.rb', line 95 def filters? return true if @options. return true if @options. false end |
#skip?(direction, step, platform) ⇒ Boolean
Determines whether to skip a step
32 33 34 35 36 37 38 |
# File 'lib/gene_system/commands/helpers.rb', line 32 def skip?(direction, step, platform) return false if step.send(direction).skip.nil? platform.execute_command( step.send(direction).skip ).zero? end |
#steps ⇒ GeneSystem::StepCollection
Returns manifest steps that match command options
If there are no inclusions or exclusions then all of the steps are returned.
If there is an include and/or an exclude filter then the steps are filtered
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gene_system/commands/helpers.rb', line 52 def steps steps = @manifest.steps return steps unless filters? filters.each do |matcher, | steps = steps.filter( matcher, tags: ) end steps end |