Class: Deadpool::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/deadpool/helper.rb

Class Method Summary collapse

Class Method Details

.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/deadpool/helper.rb', line 44

def self.camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
  if first_letter_in_uppercase
    lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
  else
    lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..1]
  end
end

.configure(options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/deadpool/helper.rb', line 22

def self.configure(options)
  default_config          = YAML.load(File.read(File.join(File.dirname(__FILE__), '../../config/default_environment.yml')))
  environment_config_path = File.join(options[:config_path], 'config/environment.yml')

  if File.exists? environment_config_path
    user_config = YAML.load(File.read(File.join(options[:config_path], 'config/environment.yml')))

    if user_config
      return Deadpool::Helper.symbolize_keys default_config.merge(user_config).merge(options)
    end
  end

  return default_config
end

.setup_logger(config) ⇒ Object



37
38
39
40
41
42
# File 'lib/deadpool/helper.rb', line 37

def self.setup_logger(config)
  logger       = Logger.new(config[:log_path])
  logger.level = Logger.const_get(config[:log_level].upcase)
  
  return logger
end

.symbolize_keys(arg) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deadpool/helper.rb', line 6

def self.symbolize_keys(arg)
  case arg
  when Array
    arg.map { |elem| symbolize_keys elem }
  when Hash
    Hash[
      arg.map { |key, value|  
        k = key.is_a?(String) ? key.to_sym : key
        v = symbolize_keys value
        [k,v]
      }]
  else
    arg
  end
end