Class: Stairs::Step
- Inherits:
-
Object
- Object
- Stairs::Step
- Defined in:
- lib/stairs/step.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Choice
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #step_description ⇒ Object
- #step_title ⇒ Object
Class Method Summary collapse
Instance Method Summary collapse
- #bundle ⇒ Object
-
#choice(*args, &block) ⇒ Object
Prompt user to make a choice.
-
#env(name, value) ⇒ Object
Set or update env var.
- #finish(message) ⇒ Object
-
#initialize(options = {}) ⇒ 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(options = {}) ⇒ Step
Returns a new instance of Step.
5 6 7 |
# File 'lib/stairs/step.rb', line 5 def initialize(={}) @options = .reverse_merge required: true end |
Instance Attribute Details
#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
31 32 33 |
# File 'lib/stairs/step.rb', line 31 def step_description @step_description || self.class.step_description end |
#step_title ⇒ Object
27 28 29 |
# File 'lib/stairs/step.rb', line 27 def step_title @step_title || self.class.step_title end |
Class Method Details
.description(description) ⇒ Object
23 24 25 |
# File 'lib/stairs/step.rb', line 23 def self.description(description) self.step_description = description end |
.title(title) ⇒ Object
19 20 21 |
# File 'lib/stairs/step.rb', line 19 def self.title(title) self.step_title = title end |
Instance Method Details
#bundle ⇒ Object
52 53 54 55 56 |
# File 'lib/stairs/step.rb', line 52 def bundle stairs_info "== Running bundle" system "bundle" stairs_info "== Completed bundle" end |
#choice(*args, &block) ⇒ Object
Prompt user to make a choice
48 49 50 |
# File 'lib/stairs/step.rb', line 48 def choice(*args, &block) Choice.new(*args, &block).run end |
#env(name, value) ⇒ Object
Set or update env var
65 66 67 68 69 70 71 72 73 |
# File 'lib/stairs/step.rb', line 65 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
100 101 102 103 |
# File 'lib/stairs/step.rb', line 100 def finish() puts "== All done!".green puts .green end |
#provide(prompt, options = {}) ⇒ Object
Prompt user to provide input
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stairs/step.rb', line 36 def provide(prompt, ={}) .reverse_merge! required: true, default: nil required = [:required] && ![:default] prompt << " (leave blank for #{[:default]})" if [:default] prompt << ": " Stairs::Util::CLI.collect(prompt.blue, required: required) || [:default] end |
#rake(task) ⇒ Object
58 59 60 61 62 |
# File 'lib/stairs/step.rb', line 58 def rake(task) stairs_info "== Running #{task}" system "rake #{task}" stairs_info "== Completed #{task}" end |
#run! ⇒ Object
9 10 11 12 13 |
# File 'lib/stairs/step.rb', line 9 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
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stairs/step.rb', line 88 def setup(step_name, ={}, &block) if block_given? Step.new().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().run! end end |
#stairs_info(message) ⇒ Object
105 106 107 |
# File 'lib/stairs/step.rb', line 105 def stairs_info() puts .light_black end |
#write(string, filename) ⇒ Object
Replace contents of file
76 77 78 |
# File 'lib/stairs/step.rb', line 76 def write(string, filename) Util::FileMutation.write(string, filename) end |
#write_line(string, filename) ⇒ Object
Append line to file
81 82 83 |
# File 'lib/stairs/step.rb', line 81 def write_line(string, filename) Util::FileMutation.write_line(string, filename) end |