Class: Boson::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/boson/namespace.rb

Overview

Used in all things namespace.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, library) ⇒ Namespace

Returns a new instance of Namespace.

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/boson/namespace.rb', line 15

def initialize(name, library)
  raise ArgumentError unless library.module
  @name, @library = name.to_s, library
  class <<self; self end.send :include, @library.module
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



21
22
23
# File 'lib/boson/namespace.rb', line 21

def method_missing(method, *args, &block)
  Boson.can_invoke?(method) ? Boson.invoke(method, *args, &block) : super
end

Class Method Details

.create(name, library) ⇒ Object

Creates a namespace given its name and the library it belongs to.



10
11
12
13
# File 'lib/boson/namespace.rb', line 10

def self.create(name, library)
  namespaces[name.to_s] = new(name, library)
  Commands::Namespace.send(:define_method, name) { Boson::Namespace.namespaces[name.to_s] }
end

.namespacesObject

Hash of created namespace names to namespace objects



5
6
7
# File 'lib/boson/namespace.rb', line 5

def self.namespaces
  @namespaces ||= {}
end

Instance Method Details

#boson_commandsObject

:startdoc: List of subcommands for the namespace.



27
28
29
# File 'lib/boson/namespace.rb', line 27

def boson_commands
  @library.module.instance_methods.map {|e| e.to_s }
end