Class: Warg::Config::VariableSet

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

Defined Under Namespace

Classes: Property

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, context) ⇒ VariableSet

Returns a new instance of VariableSet.



1340
1341
1342
1343
1344
1345
# File 'lib/warg.rb', line 1340

def initialize(name, context)
  @_name = name
  @context = context
  # FIXME: make this "private" by adding an underscore
  @properties = Set.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
# File 'lib/warg.rb', line 1377

def method_missing(name, *args, &block)
  writer_name = name.to_s
  reader_name = writer_name.chomp("=")

  if reader_name !~ Property::REGEXP
    super
  elsif reader_name == writer_name && block.nil?
    $stderr.puts "`#{@_name}.#{reader_name}' was accessed before it was defined"
    nil
  elsif writer_name.end_with?("=") or not block.nil?
    value = block || args

    extend Property.new(reader_name, *value)
  end
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



1338
1339
1340
# File 'lib/warg.rb', line 1338

def context
  @context
end

Instance Method Details

#copy(other) ⇒ Object



1359
1360
1361
1362
1363
1364
1365
# File 'lib/warg.rb', line 1359

def copy(other)
  other.properties.each do |property_name|
    value = other.instance_variable_get("@#{property_name}")

    extend Property.new(property_name, value)
  end
end

#define!(property_name) ⇒ Object



1355
1356
1357
# File 'lib/warg.rb', line 1355

def define!(property_name)
  @properties << property_name.to_s
end

#defined?(property_name) ⇒ Boolean

Returns:

  • (Boolean)


1351
1352
1353
# File 'lib/warg.rb', line 1351

def defined?(property_name)
  @properties.include?(property_name.to_s)
end

#to_hObject



1367
1368
1369
1370
1371
# File 'lib/warg.rb', line 1367

def to_h
  @properties.each_with_object({}) do |property_name, variables|
    variables["#{@_name}_#{property_name}"] = send(property_name)
  end
end