Sha256: f7a8e8db6f4f74d5500dc854b35bf9c031e69ec283e75400ea4aa8827fce68a0

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module Boson
  class Namespace
    def self.create_object_namespace(name, library)
      obj = library.namespace_object
      obj.instance_eval("class<<self;self;end").send(:define_method, :boson_commands) {
        self.class.instance_methods(false) }
      obj.instance_eval("class<<self;self;end").send(:define_method, :object_delegate?) { true }
      namespaces[name.to_s] = obj
    end

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

    def self.create(name, library)
      if library.object_namespace && library.module.instance_methods.include?(name)
        library.include_in_universe
        create_object_namespace(name, library)
      else
        create_basic_namespace(name, library)
      end
    end

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

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

    def boson_commands
      @library.module.instance_methods
    end

    def object_delegate?; false; end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
boson-0.0.1 lib/boson/namespace.rb