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

Instance Method Details

#ask(prompts = []) ⇒ Object

Asks for user input when given prompts

Parameters:

  • prompts (Array) (defaults to: [])

Returns:

  • Hashie::Mash



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

#filtersHash

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

Returns:

  • (Hash)


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.include_tags if @options.include_tags

  filters[StepCollection::STEP_EXCLUDE_ANY_TAG] = @options.exclude_tags if @options.exclude_tags

  filters
end

#filters?Boolean

Returns true when an inclusion filter and/or an exclusion filter is specified in command options.

Otherwise it returns false

Returns:

  • (Boolean)


95
96
97
98
99
100
# File 'lib/gene_system/commands/helpers.rb', line 95

def filters?
  return true if @options.include_tags
  return true if @options.exclude_tags

  false
end

#skip?(direction, step, platform) ⇒ Boolean

Determines whether to skip a step

Parameters:

Returns:

  • (Boolean)


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

#stepsGeneSystem::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, tags|
    steps = steps.filter(
      matcher, tags: tags
    )
  end

  steps
end