Class: Perkins::Build::Shell::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/perkins/build/shell/node.rb

Direct Known Subclasses

Cmd, Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) {|_self| ... } ⇒ Node

Returns a new instance of Node.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
# File 'lib/perkins/build/shell/node.rb', line 10

def initialize(*args)
  @options = args.last.is_a?(Hash) ? args.pop : {}
  @level = options.delete(:level) || 0
  @code = args.first
  yield(self) if block_given?
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



8
9
10
# File 'lib/perkins/build/shell/node.rb', line 8

def code
  @code
end

#levelObject (readonly)

Returns the value of attribute level.



8
9
10
# File 'lib/perkins/build/shell/node.rb', line 8

def level
  @level
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/perkins/build/shell/node.rb', line 8

def options
  @options
end

Instance Method Details

#escape(code) ⇒ Object



25
26
27
# File 'lib/perkins/build/shell/node.rb', line 25

def escape(code)
  Shellwords.escape(code)
end

#nameObject



17
18
19
# File 'lib/perkins/build/shell/node.rb', line 17

def name
  self.class.name.split('::').last.downcase
end

#to_sObject



21
22
23
# File 'lib/perkins/build/shell/node.rb', line 21

def to_s
  code ? code.indent(level) : code
end