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



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

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

#optionsObject



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

def options
  @options ||= defaults
end

#valuesObject



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

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

Class Method Details

.configObject



178
179
180
# File 'lib/crowbar/client/config.rb', line 178

def config
  instance.config
end

.configure(options) ⇒ Object



166
167
168
# File 'lib/crowbar/client/config.rb', line 166

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

.defaultsObject



170
171
172
# File 'lib/crowbar/client/config.rb', line 170

def defaults
  instance.defaults
end

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



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/crowbar/client/config.rb', line 186

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



174
175
176
# File 'lib/crowbar/client/config.rb', line 174

def options
  instance.options
end

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

Returns:

  • (Boolean)


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/crowbar/client/config.rb', line 203

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



182
183
184
# File 'lib/crowbar/client/config.rb', line 182

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
# File 'lib/crowbar/client/config.rb', line 39

def defaults
  @defaults ||= Hashie::Mash.new(
    alias: default_alias,
    username: default_username,
    password: default_password,
    server: default_server,
    timeout: default_timeout,
    anonymous: default_anonymous,
    debug: default_debug
  )
end