Class: Boson::Library
- Inherits:
-
Object
- Object
- Boson::Library
- Defined in:
- lib/boson/library.rb
Overview
A library is a group of commands (Command objects) usually grouped together by a module. Libraries are loaded from different sources depending on the library subclass.
Creating Your Own Library
To create your own subclass you need to define what sources the subclass can handle with handles(). See Loader to see what instance methods to override for a subclass.
Direct Known Subclasses
Defined Under Namespace
Modules: API
Constant Summary collapse
- ATTRIBUTES =
Public attributes for use outside of Boson.
[:commands, :loaded, :module, :name]
Class Attribute Summary collapse
-
.handle_blocks ⇒ Object
Returns the value of attribute handle_blocks.
Instance Attribute Summary collapse
-
#lib_file ⇒ Object
readonly
Private attribute for use within Boson.
-
#new_commands ⇒ Object
readonly
Private attribute for use within Boson.
-
#new_module ⇒ Object
readonly
Private attribute for use within Boson.
Class Method Summary collapse
-
.handles(&block) ⇒ Object
Returns true when the subclass is chosen to load.
Instance Method Summary collapse
-
#clean_name ⇒ Object
handles names under directories.
-
#command_object(name) ⇒ Object
Command object for given command name.
-
#command_objects(names = self.commands, command_array = Boson.commands) ⇒ Object
Command objects of library’s commands.
-
#initialize(hash) ⇒ Library
constructor
Creates a library object with the given hash.
-
#library_type ⇒ Object
A concise symbol version of a library type i.e.
-
#set_name(name) ⇒ Object
sets name.
Methods included from API
#before_initialize, #config, #local?, #namespace_object
Methods included from Loader
#actual_load_commands, #after_include, #before_load_commands, #clean_library_commands, #detect_additions, #handle_method_conflict_error, #load, #load_commands, #load_commands?, #load_source_and_set_module, #loaded_correctly?, #method_conflicts, #module_callbacks, #set_library_commands
Constructor Details
#initialize(hash) ⇒ Library
Creates a library object with the given hash. Each hash pair maps directly to an instance variable and value. Defaults for attributes are read from config[@library_name].
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/boson/library.rb', line 40 def initialize(hash) before_initialize @name = set_name(hash.delete(:name)) or raise ArgumentError, "Library missing required key :name" @loaded = false @commands_hash = {} @commands = [] set_config (config[:libraries][@name] || {}).merge(hash), true set_command_aliases(config[:command_aliases]) end |
Class Attribute Details
.handle_blocks ⇒ Object
Returns the value of attribute handle_blocks.
13 14 15 |
# File 'lib/boson/library.rb', line 13 def handle_blocks @handle_blocks end |
Instance Attribute Details
#lib_file ⇒ Object (readonly)
Private attribute for use within Boson.
24 25 26 |
# File 'lib/boson/library.rb', line 24 def lib_file @lib_file end |
#new_commands ⇒ Object (readonly)
Private attribute for use within Boson.
24 25 26 |
# File 'lib/boson/library.rb', line 24 def new_commands @new_commands end |
#new_module ⇒ Object (readonly)
Private attribute for use within Boson.
24 25 26 |
# File 'lib/boson/library.rb', line 24 def new_module @new_module end |
Class Method Details
.handles(&block) ⇒ Object
Returns true when the subclass is chosen to load.
15 16 17 |
# File 'lib/boson/library.rb', line 15 def handles(&block) (Library.handle_blocks ||= []) << [self,block] end |
Instance Method Details
#clean_name ⇒ Object
handles names under directories
58 59 60 |
# File 'lib/boson/library.rb', line 58 def clean_name @name[/\w+$/] end |
#command_object(name) ⇒ Object
Command object for given command name
96 97 98 |
# File 'lib/boson/library.rb', line 96 def command_object(name) command_objects([name])[0] end |
#command_objects(names = self.commands, command_array = Boson.commands) ⇒ Object
Command objects of library’s commands
91 92 93 |
# File 'lib/boson/library.rb', line 91 def command_objects(names=self.commands, command_array=Boson.commands) command_array.select {|e| names.include?(e.name) && e.lib == self.name } end |
#library_type ⇒ Object
A concise symbol version of a library type i.e. FileLibrary -> :file.
52 53 54 55 |
# File 'lib/boson/library.rb', line 52 def library_type str = self.class.to_s[/::(\w+)Library$/, 1] || 'library' str.downcase.to_sym end |
#set_name(name) ⇒ Object
sets name
63 64 65 |
# File 'lib/boson/library.rb', line 63 def set_name(name) name.to_s end |