Class: Warg::Config

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

Direct Known Subclasses

Context

Defined Under Namespace

Classes: VariableSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



1222
1223
1224
1225
# File 'lib/warg.rb', line 1222

def initialize
  @hosts = HostCollection.new
  @variables_sets = Set.new
end

Instance Attribute Details

#default_userObject

Returns the value of attribute default_user.



1218
1219
1220
# File 'lib/warg.rb', line 1218

def default_user
  @default_user
end

#hostsObject

Returns the value of attribute hosts.



1219
1220
1221
# File 'lib/warg.rb', line 1219

def hosts
  @hosts
end

#variables_setsObject (readonly)

Returns the value of attribute variables_sets.



1220
1221
1222
# File 'lib/warg.rb', line 1220

def variables_sets
  @variables_sets
end

Instance Method Details

#[](name) ⇒ Object



1235
1236
1237
1238
1239
# File 'lib/warg.rb', line 1235

def [](name)
  if variables_set_defined?(name.to_s)
    instance_variable_get("@#{name}")
  end
end

#variables(name, &block) ⇒ Object



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
# File 'lib/warg.rb', line 1241

def variables(name, &block)
  variables_name = name.to_s
  ivar_name = "@#{variables_name}"

  if @variables_sets.include?(variables_name)
    variables_object = instance_variable_get(ivar_name)
  else
    @variables_sets << variables_name

    singleton_class.send(:attr_reader, variables_name)
    variables_object = instance_variable_set(ivar_name, VariableSet.new(variables_name, self))
  end

  block.call(variables_object)
end

#variables_set_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


1231
1232
1233
# File 'lib/warg.rb', line 1231

def variables_set_defined?(name)
  @variables_sets.include?(name.to_s)
end