Class: Crowbar::Client::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/crowbar/client/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject



56
57
58
# File 'lib/crowbar/client/config.rb', line 56

def config
  @config ||= Hashie::Mash.new
end

#optionsObject



52
53
54
# File 'lib/crowbar/client/config.rb', line 52

def options
  @options ||= defaults
end

#valuesObject



60
61
62
# File 'lib/crowbar/client/config.rb', line 60

def values
  @values ||= Hashie::Mash.new
end

Class Method Details

.configObject



134
135
136
# File 'lib/crowbar/client/config.rb', line 134

def config
  instance.config
end

.configure(options) ⇒ Object



122
123
124
# File 'lib/crowbar/client/config.rb', line 122

def configure(options)
  instance.configure(options)
end

.defaultsObject



126
127
128
# File 'lib/crowbar/client/config.rb', line 126

def defaults
  instance.defaults
end

.method_missing(method, *arguments, &block) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/crowbar/client/config.rb', line 142

def method_missing(method, *arguments, &block)
  case
  when method.to_s.ends_with?("=")
    key = method.to_s.gsub(/=\z/, "")

    if values.key?(key)
      values[key] = arguments.first
    else
      super
    end
  when values.key?(method)
    values[method]
  else
    super
  end
end

.optionsObject



130
131
132
# File 'lib/crowbar/client/config.rb', line 130

def options
  instance.options
end

.respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/crowbar/client/config.rb', line 159

def respond_to?(method, include_private = false)
  case
  when method.to_s.ends_with?("=")
    key = method.to_s.gsub(/=\z/, "")

    if values.key?(key)
      true
    else
      super
    end
  when values.key?(method)
    true
  else
    super
  end
end

.valuesObject



138
139
140
# File 'lib/crowbar/client/config.rb', line 138

def values
  instance.values
end

Instance Method Details

#configure(options) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/crowbar/client/config.rb', line 30

def configure(options)
  self.options = Hashie::Mash.new(
    options
  )

  self.config = parser
  self.values = merge
end

#defaultsObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/crowbar/client/config.rb', line 39

def defaults
  @defaults ||= Hashie::Mash.new(
    config: nil,
    alias: "default",
    username: "crowbar",
    password: "crowbar",
    server: "http://127.0.0.1:80",
    timeout: 60,
    anonymous: false,
    debug: false
  )
end