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.



1287
1288
1289
1290
1291
1292
# File 'lib/warg.rb', line 1287

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)



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
# File 'lib/warg.rb', line 1324

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.



1285
1286
1287
# File 'lib/warg.rb', line 1285

def context
  @context
end

Instance Method Details

#copy(other) ⇒ Object



1306
1307
1308
1309
1310
1311
1312
# File 'lib/warg.rb', line 1306

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



1302
1303
1304
# File 'lib/warg.rb', line 1302

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

#defined?(property_name) ⇒ Boolean

Returns:

  • (Boolean)


1298
1299
1300
# File 'lib/warg.rb', line 1298

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

#to_hObject



1314
1315
1316
1317
1318
# File 'lib/warg.rb', line 1314

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