Class: Rudy::Global

Inherits:
Storable
  • Object
show all
Defined in:
lib/rudy/global.rb

Overview

Rudy::Global

This global class is used by all Huxtable objects. When a new CLI global is added, the appropriate field must be added to this class (optional: a default value in initialize).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobal

Returns a new instance of Global.



45
46
47
48
49
50
51
52
53
54
# File 'lib/rudy/global.rb', line 45

def initialize
  postprocess
  # These attributes MUST have values. 
  @verbose ||= 0
  @nocolor = true unless @nocolor == "false" || @nocolor == false
  @quiet ||= false
  @format ||= :string # as in, to_s
  @print_header = true if @print_header == nil
  @yes = false if @yes.nil?
end

Instance Attribute Details

Returns the value of attribute print_header.



43
44
45
# File 'lib/rudy/global.rb', line 43

def print_header
  @print_header
end

Instance Method Details

#apply_config(config) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rudy/global.rb', line 56

def apply_config(config)
  return unless config.is_a?(Rudy::Config)
  if config.defaults?
    # Apply the "color" default before "nocolor" so nocolor has presedence
    @nocolor = !config.defaults.color unless config.defaults.color.nil?
    %w[region zone environment role position user nocolor quiet yes localhost].each do |name|
      val = config.defaults.send(name)
      self.send("#{name}=", val) unless val.nil?
    end
  end
  
  if config.accounts? && config.accounts.aws
    %w[accesskey secretkey accountnum cert privatekey].each do |name|
      val = config.accounts.aws.send(name)
      self.send("#{name}=", val) unless val.nil?
    end
  end
  
  postprocess
end

#to_s(*args) ⇒ Object



90
91
92
# File 'lib/rudy/global.rb', line 90

def to_s(*args)
  super()
end

#update(ghash = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rudy/global.rb', line 78

def update(ghash={})
  ghash = ghash.marshal_dump if ghash.is_a?(OpenStruct)
  
  if ghash.is_a?(Hash)
    ghash.each_pair { |n,v| self.send("#{n}=", v) } 
  else
    raise "Unexpected #{ghash.class.to_s}"
  end
  
  postprocess
end