Module: ConfigPlus::Helper

Defined in:
lib/config_plus/helper.rb

Class Method Summary collapse

Class Method Details

.classify(name) ⇒ Object



27
28
29
30
31
# File 'lib/config_plus/helper.rb', line 27

def classify(name)
  return name.classify if name.respond_to?(:classify)
  name.to_s.gsub(/\/+/, '::')
    .gsub(/_?([a-z]+)/) { $1.capitalize }
end

.config_for(object, config) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/config_plus/helper.rb', line 4

def config_for(object, config)
  configs = matched_configs(object, config)
  return configs.first if configs.size <= 1

  if configs.all? {|c| c.is_a? Hash }
    configs.inject(::ConfigPlus::Node.new) {|h, conf|
      ::ConfigPlus::Merger.merge(h, conf)
    }
  else
    configs.inject([]) {|a, conf| a << conf }
  end
end

.underscore(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/config_plus/helper.rb', line 17

def underscore(name)
  return name.underscore if name.respond_to?(:underscore)

  name.gsub(/::/, '.')
    .gsub(/((\A|\b)([A-Z]+))|([A-Z]+)/) do
    next $3.downcase if $3
    "_#{$4.downcase}"
  end
end