lib/boson/manager.rb in boson-0.2.0 vs lib/boson/manager.rb in boson-0.2.1
- old
+ new
@@ -2,11 +2,11 @@
# Base class for library loading errors. Raised mostly in Boson::Loader and rescued by Boson::Manager.
class LoaderError < StandardError; end
# Raised when a library's append_features returns false.
class AppendFeaturesFalseError < StandardError; end
- # Handles loading and reloading of libraries and commands.
+ # Handles loading of libraries and commands.
class Manager
class <<self
attr_accessor :failed_libraries
# Loads a library or an array of libraries with options. Manager loads the first library subclass
@@ -21,32 +21,10 @@
Array(libraries).map {|e|
(@library = load_once(e, options)) ? after_load : false
}.all?
end
- # Reloads a library or an array of libraries with the following options:
- # * :verbose: Boolean to print reload status. Default is false.
- def reload(source, options={})
- if (lib = Boson.library(source))
- if lib.loaded
- command_size = Boson.commands.size
- @options = options
- if (result = rescue_load_action(lib.name, :reload) { lib.reload })
- after_reload(lib)
- puts "Reloaded library #{source}: Added #{Boson.commands.size - command_size} commands" if options[:verbose]
- end
- result
- else
- puts "Library hasn't been loaded yet. Loading library #{source}..." if options[:verbose]
- load(source, options)
- end
- else
- puts "Library #{source} doesn't exist." if options[:verbose]
- false
- end
- end
-
#:stopdoc:
def failed_libraries
@failed_libraries ||= []
end
@@ -121,33 +99,28 @@
puts "Loaded library dependency #{e.name}" if @options[:verbose]
end
true
end
- def after_reload(lib)
- Boson.commands.delete_if {|e| e.lib == lib.name } if lib.new_module
- create_commands(lib, lib.new_commands)
- end
-
def before_create_commands(lib)
lib.is_a?(FileLibrary) && lib.module && Inspector.add_method_data_to_library(lib)
end
def create_commands(lib, commands=lib.commands)
before_create_commands(lib)
commands.each {|e| Boson.commands << Command.create(e, lib)}
create_command_aliases(lib, commands) if commands.size > 0 && !lib.no_alias_creation
- create_option_commands(lib, commands)
+ redefine_commands(lib, commands)
end
- def create_option_commands(lib, commands)
+ def redefine_commands(lib, commands)
option_commands = lib.command_objects(commands).select {|e| e.option_command? }
accepted, rejected = option_commands.partition {|e| e.args(lib) || e.arg_size }
if @options[: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.create_option_command(lib.namespace_object, cmd) }
+ accepted.each {|cmd| Scientist.redefine_command(lib.namespace_object, cmd) }
end
def create_command_aliases(lib, commands)
lib.module ? prep_and_create_instance_aliases(commands, lib.module) : check_for_uncreated_aliases(lib, commands)
end
\ No newline at end of file