Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allows namespaces to load constants on-demand

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .document
Octocat-spinner-32 .gemtest
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .yardopts
Octocat-spinner-32 ChangeLog.md
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 gemspec.yml
Octocat-spinner-32 open_namespace.gemspec
README.md

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.

Examples

Explicit and implicit loading of constants:

require 'open_namespace'

module Project
  module Plugins
    include OpenNamespace
  end
end

# explicitly load constants
Project::Plguins.require_const :foo_bar
# => Project::Plugins::FooBar

# explicitly load constants with odd capitalization
Project::Plugins.require_const :tcp_session
# => Project::Plugins::TCPSession

# explicitly load constants via sub-paths
Project::Plguins.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('project','ui','command_line','commands')
      end
    end
  end
end

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

Install

$ gem install open_namespace

License

Copyright (c) 2010-2012 Hal Brodigan

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

Something went wrong with that request. Please try again.