0.0
Low commit activity in last 3 years
There's a lot of open issues
A long-lived project that still receives updates
OpenNamespace allows namespaces to require and find classes and modules from other RubyGems.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
 Project Readme

OpenNamespace

Description

OpenNamespace allows namespaces to require and find classes and modules from RubyGems. Using OpenNamespace you can make a Plugins module able to load plugin modules/classes from other gems.

Features

  • Provides implicit loading of constants via const_defined?.
  • Provides implicit loading of constants via const_missing.
  • Provides explicit loading of constants via require_const.
  • Can auto-load other sub-gems (ex: foo-bar) from the main gem's namespace (ex: Foo).

Examples

Include it into a namespace:

require 'open_namespace'

module Project
  module Plugins
    include OpenNamespace
  end
end

Explicitly load constants via their file name:

Project::Plugins.require_const :foo_bar
# => Project::Plugins::FooBar

Explicitly load constants containing uppercase acronyms:

Project::Plugins.require_const :tcp_session
# => Project::Plugins::TCPSession

Explicitly load constants from nested directories:

Project::Plugins.require_const 'templates/erb'
# => Project::Plugins::Templates::Erb

Implicitly load constants via const_missing:

Project::Plugins::Other
# => Project::Plugins::Other

Loading constants from alternate namespace root directories:

module Project
  module UI
    module CommandLine
      module Commands
        include OpenNamespace

        self.namespace_root = File.join(__dir__,'commands')
      end
    end
  end
end

Project::UI::CommandLine::Commands.require_const :help
# => Project::UI::CommandLine::Commands::Help

Install

$ gem install open_namespace

License

See {file:LICENSE.txt} for license information.