Class: Consist::Step
- Inherits:
-
Object
- Object
- Consist::Step
- Includes:
- SSHKit::DSL
- Defined in:
- lib/consist/step.rb
Instance Method Summary collapse
- #check(status:, path: nil, file: nil, message: "", &block) ⇒ Object
- #id(id = nil) ⇒ Object
-
#initialize(id:, &block) ⇒ Step
constructor
A new instance of Step.
- #mutate_file(mode:, target_file:, match:, target_string:, delim: "/", message: "") ⇒ Object
- #name(name = nil) ⇒ Object
- #perform(executor) ⇒ Object
- #required_user(user = nil) ⇒ Object
- #shell(message = "", params: {}) ⇒ Object
- #upload_file(local_file:, remote_path:, message: "") ⇒ Object
Constructor Details
#initialize(id:, &block) ⇒ Step
Returns a new instance of Step.
9 10 11 12 13 14 |
# File 'lib/consist/step.rb', line 9 def initialize(id:, &block) @commands = [] @id = id @required_user = :root instance_eval(&block) end |
Instance Method Details
#check(status:, path: nil, file: nil, message: "", &block) ⇒ Object
48 49 50 |
# File 'lib/consist/step.rb', line 48 def check(status:, path: nil, file: nil, message: "", &block) @commands << {type: :check, message:, status:, file:, path:, block: -> { instance_eval(&block) }} end |
#id(id = nil) ⇒ Object
16 17 18 19 |
# File 'lib/consist/step.rb', line 16 def id(id = nil) @id = id if id @id end |
#mutate_file(mode:, target_file:, match:, target_string:, delim: "/", message: "") ⇒ Object
40 41 42 |
# File 'lib/consist/step.rb', line 40 def mutate_file(mode:, target_file:, match:, target_string:, delim: "/", message: "") @commands << {type: :mutate, mode:, message:, match:, target_file:, delim:, target_string:} end |
#name(name = nil) ⇒ Object
21 22 23 24 |
# File 'lib/consist/step.rb', line 21 def name(name = nil) @name = name if name @name end |
#perform(executor) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/consist/step.rb', line 52 def perform(executor) @commands.each do |command| (command[:message]) unless command[:message].empty? execable = Object.const_get("Consist::Commands::#{command[:type].capitalize}").new(command) executor.as @required_user do execable.perform!(executor) end end end |
#required_user(user = nil) ⇒ Object
26 27 28 29 |
# File 'lib/consist/step.rb', line 26 def required_user(user = nil) @required_user = user if user @required_user end |
#shell(message = "", params: {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/consist/step.rb', line 31 def shell( = "", params: {}) return unless block_given? command = yield commands = command.split(/(?<!\\)\n/).select { !_1.start_with?("#") }.compact @commands << {message:, type: :exec, commands:, params:} end |
#upload_file(local_file:, remote_path:, message: "") ⇒ Object
44 45 46 |
# File 'lib/consist/step.rb', line 44 def upload_file(local_file:, remote_path:, message: "") @commands << {message:, type: :upload, local_file:, remote_path:} end |