Parent

Files

RConfig::Config

Public Instance Methods

[](key) click to toggle source

Why the &*#^@*^&$ isn’t HashWithIndifferentAccess doing this? HashWithIndifferentAccess doesn’t override Hash’s []! That’s why it’s so destructive!

    # File lib/rconfig/config.rb, line 60
60:     def [](key)
61:       key = key.to_s if key.kind_of?(Symbol)
62:       super(key)
63:     end
default(key = self.default_key) click to toggle source

Allow hash.default => hash[‘default’] without breaking Hash’s usage of default(key)

    # File lib/rconfig/config.rb, line 68
68:     def default(key = self.default_key)
69:       key = key.to_s if key.is_a?(Symbol)
70:       if key == self.default_key 
71:         self['default'] if key?('default')
72:       else
73:         hash_default(key)
74:       end
75:     end
method_missing(method, *args) click to toggle source

Dotted notation can be used with arguments (useful for creating mock objects) in the YAML file the method name is a key, argument(s) form a nested key, so that the correct value is retrieved and returned.

For example loading to variable foo a yaml file that looks like: customer:

  id: 12345678
  verified:
    phone: verified
    :address: info_not_available
    ? [name, employer]
    : not_verified

Allows the following calls: foo.customer.id => 12345678 foo.customer.verified.phone => verified foo.customer.verified(“phone”) => verified foo.customer.verified(:address) => info_not_available foo.customer.verified(“name”, “employer”) => not_verified

Note that :address is specified as a symbol, where phone is just a string. Depending on what kind of parameter the method being mocked out is going to be called with, define in the YAML file either a string or a symbol. This also works inside the composite array keys.

    # File lib/rconfig/config.rb, line 42
42:     def method_missing(method, *args)
43:       method = method.to_s
44:       return if method == 'default_key'
45:       value = self[method]
46:       case args.size
47:       when 0  # e.g.: RConfig.application.method
48:         value
49:       when 1  # e.g.: RConfig.application.method(one_arg)
50:         value.send(args[0])
51:       else    # e.g.: RConfig.application.method(arg_one, args_two, ...)
52:         value[args]
53:       end
54:     end
unknown click to toggle source

HashWithIndifferentAccess#default is broken in early versions of Rails. This is defined to use the hash version in Config#default

    # File lib/rconfig/config.rb, line 15
15:     define_method(:hash_default, Hash.instance_method(:default))

Protected Instance Methods

convert_value(value) click to toggle source

Override HashWithIndifferentAccess#convert_value return instance of Config for Hash values.

    # File lib/rconfig/config.rb, line 82
82:     def convert_value(value)
83:       value.is_a?(Hash) ? self.class.new(value).freeze : super
84:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.