Module: ClassX::Pluggable::Util

Included in:
ClassMethods
Defined in:
lib/classx/pluggable.rb

Class Method Summary collapse

Class Method Details

.module2path(mod) ⇒ Object



147
148
149
150
151
# File 'lib/classx/pluggable.rb', line 147

def module2path mod
  mod.split(/::/).map { |s|
    s.gsub(/([A-Z][a-z]+)(?=[A-Z][a-z]*?)/, '\1_').gsub(/([A-Z])(?=[A-Z][a-z]+)/, '\1_').downcase
  }.join(File::SEPARATOR)
end

.nested_autoload(mod, path) ⇒ Object



162
163
164
165
166
167
168
169
170
# File 'lib/classx/pluggable.rb', line 162

def nested_autoload mod, path
  name_spaces = mod.split(/::/)
  target = name_spaces.pop
  tmp = ::Object
  name_spaces.each do |const|
    tmp = tmp.const_get(const)
  end
  tmp.autoload(target, path)
end

.nested_const_get(mod) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/classx/pluggable.rb', line 153

def nested_const_get mod
  name_spaces = mod.split(/::/)
  result = ::Object
  name_spaces.each do |const|
    result = result.const_get(const)
  end
  return result
end