Class: Boson::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/boson/runner.rb

Overview

Base class for runners.

Direct Known Subclasses

BinRunner, ConsoleRunner

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.debugObject

Returns the value of attribute debug.



5
6
7
# File 'lib/boson/runner.rb', line 5

def debug
  @debug
end

Class Method Details

.add_load_pathObject



49
50
51
52
53
54
55
# File 'lib/boson/runner.rb', line 49

def add_load_path
  Boson.repos.each {|repo|
    if repo.config[:add_load_path] || File.exists?(File.join(repo.dir, 'lib'))
      $: <<  File.join(repo.dir, 'lib') unless $:.include? File.expand_path(File.join(repo.dir, 'lib'))
    end
  }
end

.all_librariesObject

Libraries specified in config files and detected_libraries



25
26
27
# File 'lib/boson/runner.rb', line 25

def all_libraries
  Boson.repos.map {|e| e.all_libraries }.flatten.uniq
end

.autoload_command(cmd, opts = {:verbose=>verbose?}) ⇒ Object



61
62
63
64
65
# File 'lib/boson/runner.rb', line 61

def autoload_command(cmd, opts={:verbose=>verbose?})
  Index.read
  (lib = Index.find_library(cmd)) && Manager.load(lib, opts)
  lib
end

.default_librariesObject

Libraries that come with Boson



15
16
17
# File 'lib/boson/runner.rb', line 15

def default_libraries
  Boson.repos.map {|e| e.config[:defaults] || [] }.flatten + [Boson::Commands::Core, Boson::Commands::WebCore]
end

.define_autoloaderObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/boson/runner.rb', line 67

def define_autoloader
  class << ::Boson.main_object
    def method_missing(method, *args, &block)
      if Runner.autoload_command(method.to_s)
        send(method, *args, &block) if respond_to?(method)
      else
        super
      end
    end
  end
end

.detected_librariesObject

Libraries detected in repositories



20
21
22
# File 'lib/boson/runner.rb', line 20

def detected_libraries
  Boson.repos.map {|e| e.detected_libraries }.flatten.uniq
end

.in_shell=(val) ⇒ Object



45
46
47
# File 'lib/boson/runner.rb', line 45

def in_shell=(val)
  @in_shell = val
end

.in_shell?Boolean

Returns true if commands are being executed from a non-ruby shell i.e. bash. Returns false if in a ruby shell i.e. irb.

Returns:

  • (Boolean)


31
32
33
# File 'lib/boson/runner.rb', line 31

def in_shell?
  !!@in_shell
end

.initObject

Enables view, adds local load path and loads default_libraries



8
9
10
11
12
# File 'lib/boson/runner.rb', line 8

def init
  View.enable
  add_load_path
  Manager.load default_libraries, load_options
end

.load_optionsObject



57
58
59
# File 'lib/boson/runner.rb', line 57

def load_options
  {:verbose=>@options[:verbose]}
end

.verbose=(val) ⇒ Object

:stopdoc:



41
42
43
# File 'lib/boson/runner.rb', line 41

def verbose=(val)
  @verbose = val
end

.verbose?Boolean

Returns true if in commandline with verbose flag or if set explicitly. Useful in plugins.

Returns:

  • (Boolean)


36
37
38
# File 'lib/boson/runner.rb', line 36

def verbose?
  @verbose.nil? ? Boson.const_defined?(:BinRunner) && BinRunner.options[:verbose] : @verbose
end