Class: Capissh::Command::Tree
- Inherits:
-
Object
- Object
- Capissh::Command::Tree
- Includes:
- Enumerable
- Defined in:
- lib/capissh/command/tree.rb
Defined Under Namespace
Classes: Branch, ConditionBranch
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#fallback ⇒ Object
readonly
Returns the value of attribute fallback.
Class Method Summary collapse
-
.twig(config, command, &block) ⇒ Object
A tree with only one branch.
Instance Method Summary collapse
- #base_command_and_callback(server) ⇒ Object
- #branches_for(server) ⇒ Object
- #each {|fallback| ... } ⇒ Object
- #else(command, &block) ⇒ Object
-
#initialize(config) {|_self| ... } ⇒ Tree
constructor
A new instance of Tree.
- #when(condition, command, options = {}, &block) ⇒ Object
Constructor Details
#initialize(config) {|_self| ... } ⇒ Tree
Returns a new instance of Tree.
94 95 96 97 98 |
# File 'lib/capissh/command/tree.rb', line 94 def initialize(config) @configuration = config @branches = [] yield self if block_given? end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
5 6 7 |
# File 'lib/capissh/command/tree.rb', line 5 def branches @branches end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/capissh/command/tree.rb', line 4 def configuration @configuration end |
#fallback ⇒ Object (readonly)
Returns the value of attribute fallback.
6 7 8 |
# File 'lib/capissh/command/tree.rb', line 6 def fallback @fallback end |
Class Method Details
.twig(config, command, &block) ⇒ Object
A tree with only one branch.
90 91 92 |
# File 'lib/capissh/command/tree.rb', line 90 def self.twig(config, command, &block) new(config) { |t| t.else(command, &block) } end |
Instance Method Details
#base_command_and_callback(server) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/capissh/command/tree.rb', line 121 def base_command_and_callback(server) branches_for(server).map do |branch| command = branch.command if configuration command = configuration.placeholder_callback.call(command, server) end [command, branch.callback] end end |
#branches_for(server) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/capissh/command/tree.rb', line 108 def branches_for(server) seen_last = false matches = branches.select do |branch| success = !seen_last && !branch.skip? && branch.match(server) seen_last = success && branch.last? success end matches << fallback if matches.empty? && fallback return matches end |
#each {|fallback| ... } ⇒ Object
131 132 133 134 135 |
# File 'lib/capissh/command/tree.rb', line 131 def each branches.each { |branch| yield branch } yield fallback if fallback return self end |
#else(command, &block) ⇒ Object
104 105 106 |
# File 'lib/capissh/command/tree.rb', line 104 def else(command, &block) @fallback = Branch.new(command, {}, block) end |
#when(condition, command, options = {}, &block) ⇒ Object
100 101 102 |
# File 'lib/capissh/command/tree.rb', line 100 def when(condition, command, ={}, &block) branches << ConditionBranch.new(configuration, condition, command, , block) end |