module Configurethis

Constants

VERSION

Public Class Methods

root_path=(path) click to toggle source
# File lib/configurethis.rb, line 9
def root_path=(path)
  ConfigurethisProperties.root_path = path
end
use_defaults() click to toggle source
# File lib/configurethis.rb, line 13
def use_defaults
  ConfigurethisProperties.use_defaults
end

Public Instance Methods

configuration_path() click to toggle source
# File lib/configurethis.rb, line 18
def configuration_path
  configuration.path
end
configure_this_with(path) click to toggle source
# File lib/configurethis.rb, line 37
def configure_this_with(path)
  @configuration_file = path
end
method_missing(method, *args) click to toggle source
# File lib/configurethis.rb, line 41
def method_missing(method, *args)
  configuration[method.to_s]
end
reload_configuration() click to toggle source
# File lib/configurethis.rb, line 45
def reload_configuration
  @configuration = nil
  return self
end
set_root=(key) click to toggle source
# File lib/configurethis.rb, line 22
def set_root=(key)
  configuration.root = key.to_s
end
test_with(values) click to toggle source

Meant for testing different scenarios and avoid using the real configuration values in your tests/specs.

To use, pass a hash that represents the values you like so that it mirrors the yml files structure.

# File lib/configurethis.rb, line 33
def test_with(values)
  @configuration = MockConfiguration.new values
end

Protected Instance Methods

configuration() click to toggle source
# File lib/configurethis.rb, line 50
def configuration
  @configuration ||= Configuration.new(configuration_file)
end

Private Instance Methods

configuration_file() click to toggle source
# File lib/configurethis.rb, line 55
def configuration_file
  @configuration_file ||= underscore(self.to_s) + '.yml'
end
underscore(camel_cased_word) click to toggle source

Borrowed from activesupport/lib/active_support/inflector/methods.rb No need to bring in ActiveSupport for just this.

# File lib/configurethis.rb, line 62
def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!('::', '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end