module Greener::Utils

Useful shared utils

Public Instance Methods

checker_from_string(str) click to toggle source
# File lib/greener/utils.rb, line 4
def checker_from_string(str)
  namespaced = str.gsub("/", "::")
  constantize "Greener::Checker::#{namespaced}"
rescue NameError
  raise Error::Standard, "Unknown checker specified: #{str}" # TODO: print warning instead of failing
end
formatter_from_string(str) click to toggle source
# File lib/greener/utils.rb, line 11
def formatter_from_string(str)
  constantize "Greener::Formatter::#{str}"
rescue NameError
  raise Error::Standard, "Unknown formatter specified: #{str}" # TODO: print warning instead of failing
end

Private Instance Methods

constantize(camel_cased_word) click to toggle source

Borrowed from Rails

# File lib/greener/utils.rb, line 20
def constantize(camel_cased_word)
  names = camel_cased_word.split("::")
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end