Module: Kangaroo::Util::Loader::Namespace

Defined in:
lib/kangaroo/util/loader/namespace.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(const_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kangaroo/util/loader/namespace.rb', line 17

def const_missing const_name
  namespaced_const_name = "#{name}::#{const_name}"

  if namespace.model_exists?(namespaced_const_name)
    namespace.load_model(namespaced_const_name)
  elsif namespace.models_in?(namespaced_const_name)
    Module.new.tap do |mod|
      mod.send :extend, Namespace
      const_set const_name, mod
    end
  else
    super
  end
rescue
  super
end

#inspectObject



5
6
7
# File 'lib/kangaroo/util/loader/namespace.rb', line 5

def inspect
  "Module '#{name}' contains loaded OpenERP Models/Namespaces: #{constants.join(', ')}"
end

#namespaceObject



13
14
15
# File 'lib/kangaroo/util/loader/namespace.rb', line 13

def namespace
  namespace_name.constantize
end

#namespace_nameObject



9
10
11
# File 'lib/kangaroo/util/loader/namespace.rb', line 9

def namespace_name
  name.match(/^([^\:]+)/)[1]
end