Sha256: 3199c2d935982962cf3c7ded62ee263c47025ccb9aae0cc3cd4733556d475564

Contents?: true

Size: 898 Bytes

Versions: 1

Compression:

Stored size: 898 Bytes

Contents

module Kangaroo
  module Util
    class Loader
      module Namespace
        def inspect
          "Module '#{name}' contains loaded OpenERP Models/Namespaces: #{constants.join(', ')}"
        end
      
        def namespace_name
          name.match(/^([^\:]+)/)[1]
        end
      
        def namespace
          namespace_name.constantize
        end
      
        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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kangaroo-0.0.3 lib/kangaroo/util/loader/namespace.rb