Class Boson::Repo

  1. lib/boson/repo.rb
Parent: Object

A class for repositories. A repository has a root directory with required subdirectories config/ and commands/ and optional subdirectory lib/. Each repository has a primary config file at config/boson.yml.


config [RW]
dir [RW]

Public class methods

new (dir)

Creates a repository given a root directory.

[show source]
# File lib/boson/repo.rb, line 12
    def initialize(dir)
      @dir = dir

Public instance methods

commands_dir ()

Points to the commands/ subdirectory and is automatically created when called. Used for command libraries.

[show source]
# File lib/boson/repo.rb, line 31
    def commands_dir
      @commands_dir ||= (cdir = self.class.commands_dir(@dir)) && FileUtils.mkdir_p(cdir) && cdir
config (reload=false)

A hash read from the YAML config file at config/boson.yml. See here for an example config file. Top level config keys, library attributes and config attributes need to be symbols.

Config keys for all repositories:

Hash of libraries mapping their name to attribute hashes. See for configurable attributes.
Hash of commands names and their aliases. Since this is global it will be read by all libraries. This is useful for quickly creating aliases without having to worry about placing them under the correct library config. For non-global aliasing, aliases should be placed under the :command_aliases key of a library entry in :libraries.
 :command_aliases=>{'libraries'=>'lib', 'commands'=>'com'}
Array of libraries to load at start up for commandline and irb. This is useful for extending boson i.e. adding your own option types since these are loaded before any other libraries. Default is no libraries.
Array of libraries to load at start up when used in irb. Default is to load all library files and libraries defined in the config.
Array of libraries to load at start up when used from the commandline. Default is no libraries.
Boolean specifying whether to add a load path pointing to the lib subdirectory/. This is useful in sharing classes between libraries without resorting to packaging them as gems. Defaults to false if the lib subdirectory doesn’t exist in the boson directory.

Config keys specific to the main repo config ~/.boson/config/boson.yml

Hash of options available to all option commands for piping (see Pipe). A pipe option has the normal option attributes and these:
  • :pipe: Specifies the command to call when piping. Defaults to the pipe’s option name.
  • :filter: Boolean which indicates that the pipe command will modify its input with what it returns. Default is false.
Hash of render options available to all option commands to be passed to a Hirb view (see View). Since this merges with default render options, it’s possible to override default render options.
Boolean specifying library loading behavior when its methods conflicts with existing methods in the global namespace. When set to false, Boson automatically puts the library in its own namespace. When set to true, the library fails to load explicitly. Default is false.
Console to load when using —console from commandline. Default is irb.
Boolean which automatically namespaces all user-defined libraries. Be aware this can break libraries which depend on commands from other libraries. Default is false.
Array of directories to ignore when detecting local repositories for Boson.local_repo.
When set, turns off commandline auto-rendering of a command’s output. Default is false.
When set, OptionParser option values (with :values or :keys) are auto aliased with underscore searching. Default is true. See Util.underscore_search.
[show source]
# File lib/boson/repo.rb, line 75
    def config(reload=false)
      if reload || @config.nil?
          @config = {:libraries=>{}, :command_aliases=>{}, :console_defaults=>[], :option_underscore_search=>true}
          @config.merge!(YAML::load_file(config_file(true))) if File.exists?(config_file)
        rescue ArgumentError
          message = $!.message !~ /syntax error on line (\d+)/ ? "Error"+$!.message :
            "Error: Syntax error in line #{$1} of config file '#{config_file}'"
          Kernel.abort message
config_dir ()

Points to the config/ subdirectory and is automatically created when called. Used for config files.

[show source]
# File lib/boson/repo.rb, line 17
    def config_dir
      @config_dir ||= FileUtils.mkdir_p(config_dir_path) && config_dir_path
config_dir_path ()
[show source]
# File lib/boson/repo.rb, line 21
    def config_dir_path
config_file (create_dir=false)

Path name of main config file. If passed true, parent directory of file is created.

[show source]
# File lib/boson/repo.rb, line 26
    def config_file(create_dir=false)
      File.join((create_dir ? config_dir : config_dir_path), 'boson.yml')
update_config () {|config| ...}

Updates main config file by passing config into a block to be modified and then saved

[show source]
# File lib/boson/repo.rb, line 90
    def update_config