lib/boson.rb in boson-0.1.0 vs lib/boson.rb in boson-0.2.0
- old
+ new
@@ -2,13 +2,24 @@
%w{hirb alias}.each {|e| require e }
%w{runner runners/console_runner repo manager loader inspector library}.each {|e| require "boson/#{e}" }
%w{argument method comment}.each {|e| require "boson/inspectors/#{e}_inspector" }
# order of library subclasses matters
%w{module file gem require}.each {|e| require "boson/libraries/#{e}_library" }
-%w{namespace view command util commands option_parser index scientist}.each {|e| require "boson/#{e}" }
+(%w{namespace view command util commands option_parser options} +
+ %w{index scientist}).each {|e| require "boson/#{e}" }
# This module stores the libraries, commands, repos and main object used throughout Boson.
+#
+# Useful documentation links:
+# * Boson::BinRunner - Runs the boson executable
+# * Boson::ConsoleRunner - Runs Boson from the ruby console
+# * Boson::Repo.config - Explains main config file
+# * Boson::Library - All about libraries
+# * Boson::FileLibrary - Explains creating libraries as files
+# * Boson::Loader - Explains library module callbacks
+# * Boson::OptionParser - All about options
+# * Boson::Scientist - Explains how commands can be both shell-commands and normal ruby methods
module Boson
# Module which is extended by Boson.main_object to give it command functionality.
module Universe; include Commands::Namespace; end
extend self
# The object which holds and executes all command functionality
@@ -26,11 +37,11 @@
@commands ||= Array.new
end
# The main required repository which defaults to ~/.boson.
def repo
- @repo ||= Repo.new("#{ENV['HOME']}/.boson")
+ @repo ||= Repo.new("#{Util.find_home}/.boson")
end
# An optional local repository which defaults to ./lib/boson or ./.boson.
def local_repo
@local_repo ||= begin
@@ -62,12 +73,19 @@
# Invoke an action on the main object.
def invoke(*args, &block)
main_object.send(*args, &block)
end
+ # Invoke command string even with namespaces
+ def full_invoke(cmd, args) #:nodoc:
+ command, subcommand = cmd.include?('.') ? cmd.split('.', 2) : [cmd, nil]
+ dispatcher = subcommand ? Boson.invoke(command) : Boson.main_object
+ dispatcher.send(subcommand || command, *args)
+ end
+
# Boolean indicating if the main object can invoke the given method/command.
- def can_invoke?(meth)
- Boson.main_object.respond_to? meth
+ def can_invoke?(meth, priv=true)
+ Boson.main_object.respond_to? meth, priv
end
end
Boson.main_object = self
\ No newline at end of file