Class: Stairs::Step
- Inherits:
-
Object
- Object
- Stairs::Step
- Defined in:
- lib/stairs/step.rb
Direct Known Subclasses
InteractiveConfiguration, Stairs::Steps::Facebook, Stairs::Steps::Postgresql, Stairs::Steps::SecretKeyBase
Defined Under Namespace
Classes: Choice
Instance Attribute Summary collapse
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #step_description ⇒ Object
- #step_title ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
-
#choice(*args, &block) ⇒ Object
Prompt user to make a choice.
-
#env(name, value) ⇒ Object
Set or update env var.
- #finish(message) ⇒ Object
- #group(*names) ⇒ Object
-
#initialize(*args) ⇒ Step
constructor
A new instance of Step.
-
#provide(prompt, options = {}) ⇒ Object
Prompt user to provide input.
- #rake(task) ⇒ Object
- #run! ⇒ Object
-
#setup(step_name, options = {}, &block) ⇒ Object
Embed a step where step_name is a symbol that can be resolved to a class in Stairs::Steps or a block is provided to be executed in an instance of Step.
- #stairs_info(message) ⇒ Object
-
#write(string, filename) ⇒ Object
Replace contents of file.
-
#write_line(string, filename) ⇒ Object
Append line to file.
Constructor Details
#initialize(*args) ⇒ Step
Returns a new instance of Step.
5 6 7 8 9 10 |
# File 'lib/stairs/step.rb', line 5 def initialize(*args) = args. @options = .reverse_merge required: true @groups = args.first end |
Instance Attribute Details
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
3 4 5 |
# File 'lib/stairs/step.rb', line 3 def groups @groups end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/stairs/step.rb', line 3 def @options end |
#step_description ⇒ Object
34 35 36 |
# File 'lib/stairs/step.rb', line 34 def step_description @step_description || self.class.step_description end |
#step_title ⇒ Object
30 31 32 |
# File 'lib/stairs/step.rb', line 30 def step_title @step_title || self.class.step_title end |
Class Method Details
.description(description) ⇒ Object
26 27 28 |
# File 'lib/stairs/step.rb', line 26 def self.description(description) self.step_description = description end |
.title(title) ⇒ Object
22 23 24 |
# File 'lib/stairs/step.rb', line 22 def self.title(title) self.step_title = title end |
Instance Method Details
#choice(*args, &block) ⇒ Object
Prompt user to make a choice
55 56 57 |
# File 'lib/stairs/step.rb', line 55 def choice(*args, &block) Choice.new(*args, &block).run end |
#env(name, value) ⇒ Object
Set or update env var
66 67 68 69 70 71 72 73 74 |
# File 'lib/stairs/step.rb', line 66 def env(name, value) ENV[name] = value if value Stairs.configuration.env_adapter.set name, value else Stairs.configuration.env_adapter.unset name end end |
#finish(message) ⇒ Object
105 106 107 108 |
# File 'lib/stairs/step.rb', line 105 def finish() puts "== All done!".green puts .green end |
#group(*names) ⇒ Object
101 102 103 |
# File 'lib/stairs/step.rb', line 101 def group(*names) yield if !groups || (names & groups).any? end |
#provide(prompt, options = {}) ⇒ Object
Prompt user to provide input
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stairs/step.rb', line 39 def provide(prompt, ={}) .reverse_merge! required: true, default: nil required = [:required] && ![:default] prompt << " (leave blank for #{[:default]})" if [:default] prompt << ": " if Stairs.configuration.use_defaults && [:default] [:default] else Stairs::Util::CLI.collect(prompt.blue, required: required) || [:default] end end |
#rake(task) ⇒ Object
59 60 61 62 63 |
# File 'lib/stairs/step.rb', line 59 def rake(task) stairs_info "== Running #{task}" system "rake #{task}" stairs_info "== Completed #{task}" end |
#run! ⇒ Object
12 13 14 15 16 |
# File 'lib/stairs/step.rb', line 12 def run! stairs_info "== Running #{step_title}" run if run_step? stairs_info "== Completed #{step_title}" end |
#setup(step_name, options = {}, &block) ⇒ Object
Embed a step where step_name is a symbol that can be resolved to a class in Stairs::Steps or a block is provided to be executed in an instance of Step
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/stairs/step.rb', line 89 def setup(step_name, ={}, &block) if block_given? Step.new(groups, ).tap do |step| step.define_singleton_method :run, &block step.step_title = step_name.to_s.titleize end.run! else klass = "Stairs::Steps::#{step_name.to_s.camelize}".constantize klass.new(groups, ).run! end end |
#stairs_info(message) ⇒ Object
110 111 112 |
# File 'lib/stairs/step.rb', line 110 def stairs_info() puts .light_black end |
#write(string, filename) ⇒ Object
Replace contents of file
77 78 79 |
# File 'lib/stairs/step.rb', line 77 def write(string, filename) Util::FileMutation.write(string, filename) end |
#write_line(string, filename) ⇒ Object
Append line to file
82 83 84 |
# File 'lib/stairs/step.rb', line 82 def write_line(string, filename) Util::FileMutation.write_line(string, filename) end |