Module: Perkins::Build::Shell::Dsl
- Included in:
- Group
- Defined in:
- lib/perkins/build/shell/dsl.rb
Instance Method Summary collapse
- #cd(path) ⇒ Object
- #cmd(code, *args) ⇒ Object
-
#echo(string, options = {}) ⇒ Object
alias set export.
- #elif(*args, &block) ⇒ Object
- #else(*args, &block) ⇒ Object
- #export(name, value, options = {}) ⇒ Object
- #file(path, content) ⇒ Object
- #fold(name, &block) ⇒ Object
- #if(*args, &block) ⇒ Object
- #newline ⇒ Object
- #raw(code, *args) ⇒ Object
- #script(*args, &block) ⇒ Object
- #set(name, value, options = {}) ⇒ Object
Instance Method Details
#cd(path) ⇒ Object
41 42 43 |
# File 'lib/perkins/build/shell/dsl.rb', line 41 def cd(path) cmd "cd #{path}", echo: true, timing: false end |
#cmd(code, *args) ⇒ Object
10 11 12 13 14 |
# File 'lib/perkins/build/shell/dsl.rb', line 10 def cmd(code, *args) = args.last.is_a?(Hash) ? args.last : {} node = Cmd.new(code, *(args)) [:fold] ? fold([:fold]) { raw(node) } : raw(node) end |
#echo(string, options = {}) ⇒ Object
alias set export
32 33 34 35 |
# File 'lib/perkins/build/shell/dsl.rb', line 32 def echo(string, = {}) string = ansi(string, ) if [:ansi] cmd "echo -e #{escape(string)}", { assert: false, echo: false, timing: false }.merge() end |
#elif(*args, &block) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/perkins/build/shell/dsl.rb', line 57 def elif(*args, &block) raise InvalidParent.new(Elif, If, nodes.last.class) unless nodes.last.is_a?(If) args = (args) els_ = args.last.delete(:else) nodes.last.raw Elif.new(*args, &block) self.else(els_, args.last) if els_ nodes.last end |
#else(*args, &block) ⇒ Object
66 67 68 69 70 |
# File 'lib/perkins/build/shell/dsl.rb', line 66 def else(*args, &block) raise InvalidParent.new(Else, If, nodes.last.class) unless nodes.last.is_a?(If) nodes.last.raw Else.new(*(args), &block) nodes.last end |
#export(name, value, options = {}) ⇒ Object
23 24 25 |
# File 'lib/perkins/build/shell/dsl.rb', line 23 def export(name, value, = {}) cmd "export #{name}=#{value}", { assert: false, timing: false }.merge() end |
#file(path, content) ⇒ Object
45 46 47 |
# File 'lib/perkins/build/shell/dsl.rb', line 45 def file(path, content) raw "echo #{escape(content)} > #{path}" end |
#fold(name, &block) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/perkins/build/shell/dsl.rb', line 72 def fold(name, &block) raw "travis_fold start #{name}" result = yield(self) raw "travis_fold end #{name}" result end |
#if(*args, &block) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/perkins/build/shell/dsl.rb', line 49 def if(*args, &block) args = (args) els_ = args.last.delete(:else) nodes << If.new(*args, &block) self.else(els_, args.last) if els_ nodes.last end |
#newline ⇒ Object
37 38 39 |
# File 'lib/perkins/build/shell/dsl.rb', line 37 def newline raw 'echo' end |
#raw(code, *args) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/perkins/build/shell/dsl.rb', line 16 def raw(code, *args) args = (args) pos = args.last.delete(:pos) || -1 node = code.is_a?(Node) ? code : Node.new(code, *args) nodes.insert(pos, node) end |
#script(*args, &block) ⇒ Object
5 6 7 8 |
# File 'lib/perkins/build/shell/dsl.rb', line 5 def script(*args, &block) nodes << Script.new(*(args), &block) nodes.last end |
#set(name, value, options = {}) ⇒ Object
27 28 29 |
# File 'lib/perkins/build/shell/dsl.rb', line 27 def set(name, value, = {}) cmd "export #{name}=#{value}", { assert: false, timing: false }.merge() end |