Class: Boson::Manager
Overview
Handles loading of libraries and commands.
Defined Under Namespace
Modules: API
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Instance Attribute Summary collapse
-
#failed_libraries ⇒ Object
Returns the value of attribute failed_libraries.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
-
.add_library(lib) ⇒ Object
Adds a library to Boson.libraries.
-
.load(libraries, options = {}) ⇒ Object
Loads a library or an array of libraries with options.
-
.loaded?(lib_name) ⇒ Boolean
Given a library name, determines if it’s loaded.
Instance Method Summary collapse
-
#add_failed_library(library) ⇒ Object
Adds a library to the failed list.
-
#after_load ⇒ Object
Called after a library is loaded.
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
-
#load(libraries, options = {}) ⇒ Object
Loads libraries.
-
#redefine_commands(lib, commands) ⇒ Object
Redefines commands.
Methods included from API
#after_create_commands, #before_create_commands, #during_after_load, #handle_load_action_error, #load_dependencies
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
39 40 41 |
# File 'lib/boson/manager.rb', line 39 def initialize @failed_libraries = [] end |
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
21 22 23 |
# File 'lib/boson/manager.rb', line 21 def instance @instance end |
Instance Attribute Details
#failed_libraries ⇒ Object
Returns the value of attribute failed_libraries.
38 39 40 |
# File 'lib/boson/manager.rb', line 38 def failed_libraries @failed_libraries end |
#verbose ⇒ Object
Returns the value of attribute verbose.
38 39 40 |
# File 'lib/boson/manager.rb', line 38 def verbose @verbose end |
Class Method Details
.add_library(lib) ⇒ Object
Adds a library to Boson.libraries
28 29 30 31 |
# File 'lib/boson/manager.rb', line 28 def self.add_library(lib) Boson.libraries.delete(Boson.library(lib.name)) Boson.libraries << lib end |
.load(libraries, options = {}) ⇒ Object
Loads a library or an array of libraries with options. Manager loads the first library subclass to return true for Library#handles. Any options that aren’t listed here are passed as library attributes to the libraries (see Library.new)
17 18 19 |
# File 'lib/boson/manager.rb', line 17 def self.load(libraries, ={}) instance.load(libraries, ) end |
Instance Method Details
#add_failed_library(library) ⇒ Object
Adds a library to the failed list
51 52 53 |
# File 'lib/boson/manager.rb', line 51 def add_failed_library(library) failed_libraries << library end |
#after_load ⇒ Object
Called after a library is loaded
56 57 58 59 60 61 62 |
# File 'lib/boson/manager.rb', line 56 def after_load create_commands(@library) self.class.add_library(@library) puts "Loaded library #{@library.name}" if verbose during_after_load true end |
#load(libraries, options = {}) ⇒ Object
Loads libraries
44 45 46 47 48 |
# File 'lib/boson/manager.rb', line 44 def load(libraries, ={}) Array(libraries).map {|e| (@library = load_once(e, )) ? after_load : false }.all? end |
#redefine_commands(lib, commands) ⇒ Object
Redefines commands
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/boson/manager.rb', line 65 def redefine_commands(lib, commands) option_commands = lib.command_objects(commands).select(&:option_command?) accepted, rejected = option_commands.partition {|e| e.args(lib) || e.arg_size } if verbose && rejected.size > 0 puts "Following commands cannot have options until their arguments " + "are configured: " + rejected.map {|e| e.name}.join(', ') end accepted.each {|cmd| Scientist.redefine_command(lib.namespace_object, cmd) } end |