Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/base/array.rb

Direct Known Subclasses

Add, Analyze, Build, Commit, Doc, Package, Publish, Pull, Push, Setup, Test, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Array

Returns a new instance of Array.


8
9
10
11
12
# File 'lib/base/array.rb', line 8

def initialize(env = nil)
  @env = env
  @env = Environment.new if @env.nil?
  @env = Environmnet.new unless @env.is_a?(Environment)
end

Instance Attribute Details

#envObject

Returns the value of attribute env.


6
7
8
# File 'lib/base/array.rb', line 6

def env
  @env
end

Instance Method Details

#add(command) ⇒ Object


38
39
40
# File 'lib/base/array.rb', line 38

def add(command)
  self << command unless has_command? command
end

#add_passive(command) ⇒ Object


71
72
73
# File 'lib/base/array.rb', line 71

def add_passive(command)
  add Command.new({ input: command, quiet: true, ignore_failure: true })
end

#add_quiet(command) ⇒ Object


67
68
69
# File 'lib/base/array.rb', line 67

def add_quiet(command)
  add Command.new({ input: command, quiet: true })
end

#execute(value = nil) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/base/array.rb', line 14

def execute(value = nil)
  @env = Environment.new if @env.nil?
  i = 0
  # puts "Array.execute length=#{self.length}" if defined?(DEBUG)
  while i < length

    # puts self[i].to_s if defined?(DEBUG)
    # puts "Array[#{i.to_s}]'=nil" if @env.debug? && self[i].nil?
    # puts "Array[#{i.to_s}].class=#{self[i].class.to_s}" if @env.debug? && !self[i].nil?
    # puts "Array[#{i.to_s}].to_s=#{self[i].to_s}" if @env.debug? && !self[i].nil?
    self[i] = Command.new({ input: self[i], quiet: true }) if self[i].is_a?(String)
    self[i] = Command.new(self[i]) if self[i].is_a?(Hash) && !self[i].is_a?(Command)

    value.each { |k, v| self[i][k] = v } if !value.nil? && value.is_a?(Hash)

    if self[i].is_a?(Command)
      self[i].execute
      @env.out self[i].summary
    end

    i += 1
  end
end

#has_command?(command) ⇒ Boolean

Returns:

  • (Boolean)

52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/base/array.rb', line 52

def has_command?(command)
  return true if command.is_a?(String) && !include?(command)

  if command.is_a?(Command)
    each do |c|
      if c.is_a?(String)
        return true if command[:input] == c
      elsif c[:input] == command[:input]
        return true
      end
    end
  end
  false
end

#log_debug_info(title) ⇒ Object


42
43
44
45
46
47
48
49
50
# File 'lib/base/array.rb', line 42

def log_debug_info(title)
  if defined?(DEBUG) && length.positive?
    puts
    puts title
    each { |c| puts "  #{c[:input]}" }
    # pp self
    puts
  end
end

#to_htmlObject


75
76
77
78
79
80
81
82
83
# File 'lib/base/array.rb', line 75

def to_html
  html = []
  html << "<div>"
  each do |e|
    html << e.to_html if e.respond_to?(:to_html)
  end
  html << "</div>"
  html.join
end