Module: Loquacious
- Defined in:
- lib/loquacious.rb,
lib/loquacious/utility.rb,
lib/loquacious/version.rb,
lib/loquacious/undefined.rb,
lib/loquacious/configuration.rb
Defined Under Namespace
Classes: Configuration, Undefined, Utility
Constant Summary collapse
- LIBPATH =
:stopdoc:
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
- KEEPERS =
(RUBY_PLATFORM == 'java') ? %r/^__|^object_id$|^initialize$|^instance_eval$|^singleton_method_added$|^\w+\?$/ : %r/^__|^object_id$|^initialize$|^instance_eval$|^\w+\?$/
- VERSION =
'1.9.3'
Class Attribute Summary collapse
-
.env_config ⇒ Object
These control respectively if ENV overrides are used, and which prefix is used Defaults are true and LOQ, and are declared at the bottom“.
-
.env_prefix ⇒ Object
Returns the value of attribute env_prefix.
Class Method Summary collapse
-
.configuration_for(name, &block) ⇒ Object
(also: configuration, config_for, config)
Returns the configuration associated with the given name.
-
.copy(config, &block) ⇒ Object
A helper method that will create a deep copy of a given Configuration object.
-
.defaults_for(name, &block) ⇒ Object
(also: defaults)
Set the default properties for the configuration associated with the given name.
-
.help_for(name, opts = {}) ⇒ Object
(also: help)
Returns a Help instance for the configuration associated with the given name.
-
.libpath(*args, &block) ⇒ Object
Returns the library path for the module.
-
.path(*args, &block) ⇒ Object
Returns the lpath for the module.
-
.remove(*args) ⇒ Object
This is merely a convenience method to remove methods from the Loquacious::Configuration class.
Class Attribute Details
.env_config ⇒ Object
These control respectively if ENV overrides are used, and which prefix is used Defaults are true and LOQ, and are declared at the bottom“
15 16 17 |
# File 'lib/loquacious.rb', line 15 def env_config @env_config end |
.env_prefix ⇒ Object
Returns the value of attribute env_prefix.
16 17 18 |
# File 'lib/loquacious.rb', line 16 def env_prefix @env_prefix end |
Class Method Details
.configuration_for(name, &block) ⇒ Object Also known as: configuration, config_for, config
Returns the configuration associated with the given name. If a block is given, then it will be used to create the configuration.
The same name can be used multiple times with different configuration blocks. Each different block will be used to add to the configuration; i.e. the configurations are additive.
26 27 28 |
# File 'lib/loquacious.rb', line 26 def configuration_for( name, &block ) ::Loquacious::Configuration.for(name, &block) end |
.copy(config, &block) ⇒ Object
A helper method that will create a deep copy of a given Configuration object. This method accepts either a Configuration instance or a name that can be used to lookup the Configuration instance (via the “Loquacious.configuration_for” method).
Loquacious.copy(config)
Loquacious.copy('name')
Optionally a block can be given. It will be used to modify the returned copy with the given values. The Configuration object being copied is never modified by this method.
Loquacious.copy(config) {
foo 'bar'
baz 'buz'
}
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/loquacious.rb', line 127 def copy( config, &block ) config = Configuration.for(config) unless config.instance_of? Configuration return unless config rv = Configuration.new rv.merge!(config) # deep copy rv.__desc.each do |key,desc| value = rv.__send(key) next unless value.instance_of? Configuration rv.__send("#{key}=", ::Loquacious.copy(value)) end rv.merge!(Configuration::DSL.evaluate(&block)) if block rv end |
.defaults_for(name, &block) ⇒ Object Also known as: defaults
Set the default properties for the configuration associated with the given name. A block must be provided to this method.
The same name can be used multiple times with different configuration blocks. Each block will add or modify the configuration; i.e. the configurations are additive.
40 41 42 |
# File 'lib/loquacious.rb', line 40 def defaults_for( name, &block ) ::Loquacious::Configuration.defaults_for(name, &block) end |
.help_for(name, opts = {}) ⇒ Object Also known as: help
Returns a Help instance for the configuration associated with the given name. See the Help#initialize method for the options that can be used with this method.
49 50 51 |
# File 'lib/loquacious.rb', line 49 def help_for( name, opts = {} ) ::Loquacious::Configuration.help_for(name, opts) end |
.libpath(*args, &block) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join
.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/loquacious.rb', line 58 def libpath( *args, &block ) rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) if block begin $LOAD_PATH.unshift LIBPATH rv = block.call ensure $LOAD_PATH.shift end end return rv end |
.path(*args, &block) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join
.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/loquacious.rb', line 74 def path( *args, &block ) rv = args.empty? ? PATH : ::File.join(PATH, args.flatten) if block begin $LOAD_PATH.unshift PATH rv = block.call ensure $LOAD_PATH.shift end end return rv end |
.remove(*args) ⇒ Object
This is merely a convenience method to remove methods from the Loquacious::Configuration class. Some ruby gems add lots of crap to the Kernel module, and this interferes with the configuration system. The remove method should be used to anihilate unwanted methods from the configuration class as needed.
Loquacious.remove :gem # courtesy of rubygems
Loquacious.remove :test, :file # courtesy of rake
Loquacious.remove :main # courtesy of main
Loquacious.remove :timeout # courtesy of timeout
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/loquacious.rb', line 98 def remove( *args ) args.each { |name| name = name.to_s.delete('=') code = <<-__ undef_method :#{name} rescue nil undef_method :#{name}= rescue nil __ Loquacious::Configuration.module_eval code Loquacious::Configuration::DSL.module_eval code } end |