Module: Detroit

Defined in:
lib/detroit.rb,
lib/detroit.rb,
lib/detroit/exec.rb,
lib/detroit/project.rb,
lib/detroit/assembly.rb,
lib/detroit/basic_tool.rb,
lib/detroit/ruby_utils.rb,
lib/detroit/basic_utils.rb,
lib/detroit/email_utils.rb,
lib/detroit/shell_utils.rb,
lib/detroit/toolchain/cli.rb,
lib/detroit/toolchain/config.rb,
lib/detroit/toolchain/runner.rb,
lib/detroit/toolchain/script.rb,
lib/detroit/toolchain/worker.rb

Defined Under Namespace

Modules: BasicUtils, EmailUtils, RubyUtils, ShellUtils, Toolchain, Tools Classes: Assembly, BasicTool, Emailer, Project, RubyProject, Tool

Class Method Summary collapse

Class Method Details

.assembliesHash<Symbol,Class>

Map of toolchain names to classes.

Returns:

  • (Hash<Symbol,Class>)

    All defined assemblies.



14
15
16
# File 'lib/detroit/assembly.rb', line 14

def self.assemblies
  @assemblies ||= {}
end

.assembly(name, &block) ⇒ Object

Define an assembly.

Returns:

  • nothing.



6
7
8
9
# File 'lib/detroit/assembly.rb', line 6

def self.assembly(name, &block)
  ass = Assembly.new(name, &block)
  const_set(name, ass)
end

.const_missing(name) ⇒ Object

Access to project metadata via constants.



11
12
13
# File 'lib/detroit.rb', line 11

def self.const_missing(name)
  [name.to_s.downcase] || super(name)
end

.define_tool_method(name, tool_class) ⇒ Object

Define tool method.



56
57
58
59
60
61
62
63
# File 'lib/detroit.rb', line 56

def self.define_tool_method(name, tool_class)
  (class << self; self; end).class_eval do
    # raise or skip if method_defined?(name)
    define_method(name) do |*a, &b|
      tool_class.new(*a, &b)
    end
  end
end

.metadataObject

Access to this project’s metadata.



3
4
5
6
7
8
# File 'lib/detroit.rb', line 3

def self.
  @metadata ||= (
    require 'yaml'
    YAML.load(File.new(File.dirname(__FILE__) + '/detroit.yml'))
  )
end

.project(root) ⇒ Object



5
6
7
# File 'lib/detroit/project.rb', line 5

def self.project(root)
  Project.factory(root)
end

.register_tool(tool_class) ⇒ Object

Add tool class to registry. If class name ends in ‘Tool` or `Base` it will be considered a reusable base class and not be added.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/detroit.rb', line 69

def self.register_tool(tool_class)
  name = tool_class.basename
  return if name.nil?
  return if name.empty?
  return if name =~ /Tool$/
  return if name =~ /Base$/
  tools[name.downcase] = tool_class
  Tools.const_set(name, tool_class)
  Detroit.define_tool_method(name, tool_class)
  return tool_class
end

.tool_exec(*argv) ⇒ Object

Execute a sepcific detroit tool.

Note this uses the executable gem to automatically “cli-ify” a tool class.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/detroit/exec.rb', line 8

def self.tool_exec(*argv)
  require 'executable'

  tool, stop = argv.shift.split(':')     

  raise "No tool specified." unless tool
  raise "No tool stop specified." unless stop

  begin
    require "detroit-#{tool}"
  rescue LoadError
    raise "Unknown tool. Perhaps try `gem install detroit-#{tool}`."
  end

  tool_class = Detroit.tools[tool]

  exec_class = Class.new(tool_class) do
    include Executable

    # TODO: Fix executable, to at least super if defined super.
    define_method(:initialize) do
      tool_class.instance_method(:initialize).bind(self).call
    end

    # Show this message.
    def help!
      cli.show_help
      exit
    end
    alias :h! :help!

    define_method(:call) do |*args|
      if assemble?(stop.to_sym)
        assemble(stop.to_sym)
      else
        raise "#{tool} does not know how to #{stop}."
      end
    end
  end

  #exec_class.send(:define_method, :command_name) do
  #  tool
  #end

  exec_class.run(argv)
end

.toolsObject

Tool registry.



49
50
51
# File 'lib/detroit.rb', line 49

def self.tools
  @tools ||= {}
end