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.



1249
1250
1251
1252
# File 'lib/warg.rb', line 1249

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

Instance Attribute Details

#default_userObject

Returns the value of attribute default_user.



1245
1246
1247
# File 'lib/warg.rb', line 1245

def default_user
  @default_user
end

#hostsObject

Returns the value of attribute hosts.



1246
1247
1248
# File 'lib/warg.rb', line 1246

def hosts
  @hosts
end

#variables_setsObject (readonly)

Returns the value of attribute variables_sets.



1247
1248
1249
# File 'lib/warg.rb', line 1247

def variables_sets
  @variables_sets
end

Instance Method Details

#[](name) ⇒ Object



1262
1263
1264
1265
1266
# File 'lib/warg.rb', line 1262

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

#variables(name, &block) ⇒ Object



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
# File 'lib/warg.rb', line 1268

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)


1258
1259
1260
# File 'lib/warg.rb', line 1258

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