class Detroit::Toolchain::Config

Detroit configuration.

TODO: Greatly simplify this, to support

Constants

DIRECTORY

Configuration directory name (most likely a hidden “dot” directory).

FILE_EXTENSION

File identifier used to find a project’s Assembly(s).

Attributes

assemblies[R]

The list of a project’s assembly files.

@return [Array<String>] routine files

defaults[R]

Worker defaults. This is a mapping of worker names to default settings. Very useful for when using the same worker more than once.

@return [Hash] default settings

root[R]

TODO: Should this be project instead?

workers[R]

Worker configurations from Assembly or *.assembly files.

@return [Hash]

Public Class Methods

new(root, assembly_files=nil) click to toggle source
# File lib/detroit/toolchain/config.rb, line 41
      def initialize(root, assembly_files=nil)
p "CONFIG!!!!!!!!!!!!!!!!!"
        @root = root

        if assembly_files && !assembly_files.empty?
          @assembly_filenames = assembly_files
        else
          @assembly_filenames = nil
        end

        @assemblies = {}
        @workers    = {}
        @defaults   = {}

        @loaded_plugins = {}

        load_plugins
        load_defaults
        load_assemblies
      end

Public Instance Methods

assembly_filenames() click to toggle source

If a ‘Assembly` or `.assembly` file exists, then it is returned. Otherwise all `*.assembly` files are loaded. To load `*.assembly` files from another directory add the directory to config options file.

# File lib/detroit/toolchain/config.rb, line 131
def assembly_filenames
  @assembly_filenames ||= (
    files = []
    ## match 'Assembly' or '.assembly' file
    files = root.glob("{,.,*.}#{FILE_EXTENSION}{,.rb,.yml,.yaml}", :casefold)
    ## only files
    files = files.select{ |f| File.file?(f) }
    ##
    if files.empty?
      ## match '.detroit/*.assembly' or 'detroit/*.assembly'
      files += root.glob("{,.}#{DIRECTORY}/*.#{FILE_EXTENSION}", :casefold)
      ## match 'task/*.assembly' (OLD SCHOOL)
      files += root.glob("{task,tasks}/*.#{FILE_EXTENSION}", :casefold)
      ## only files
      files = files.select{ |f| File.file?(f) }
    end
    files
  )
end
defaults=(hash) click to toggle source

Set defaults.

# File lib/detroit/toolchain/config.rb, line 124
def defaults=(hash)
  @defaults = hash.to_h
end
each(&block) click to toggle source
# File lib/detroit/toolchain/config.rb, line 152
def each(&block)
  workers.each(&block)
end
load_assemblies() click to toggle source
# File lib/detroit/toolchain/config.rb, line 95
def load_assemblies
  assembly_filenames.each do |file|
    load_assembly_file(file)
  end

  #if config = eval('self', TOPLEVEL_BINDING).rc_detroit
  #  @assemblies['(rc)'] = Assembly.new(&config)
  #  @workers.merge!(assemblies['(rc)'].workers)
  #end

  #if config = Detroit.rc_config
  #  assembly = Assembly.new do
  #    config.each do |c|
  #      track(c.profile, &c)
  #    end
  #  end
  #  @assemblies['(rc)'] = assembly
  #  @workers.merge!(assemblies['(rc)'].workers)
  #end
end
load_assembly_file(file) click to toggle source
# File lib/detroit/toolchain/config.rb, line 117
      def load_assembly_file(file)
p "HERE!!!!!!!!!"
        @assemblies[file] = Assembly::Script.load(File.new(file))
        @workers.merge!(assemblies[file].workers)
      end
load_defaults() click to toggle source

Load defaults from ‘.detroit/defaults.yml`.

# File lib/detroit/toolchain/config.rb, line 86
def load_defaults
  if file = root.glob('{.,}#{DIRECTORY}/defaults{,.yml,.yaml}').first
    self.defaults = YAML.load(File.new(file))
  else
    self.defaults = {}
  end
end
load_plugin(name) click to toggle source

Load a plugin.

# File lib/detroit/toolchain/config.rb, line 63
def load_plugin(name)
  @loaded_plugins[name] ||= (
    begin
      require "detroit-#{name}"
    rescue LoadError => e
      $stderr.puts "ERROR: #{e.message.capitalize}"
      $stderr.puts "       Perhaps `gem install detroit-#{name}`?"
      exit -1
    end
    name # true ?
  )
end
load_plugins() click to toggle source

Pre-load plugins using ‘.detroit/plugins.rb`.

# File lib/detroit/toolchain/config.rb, line 77
def load_plugins
  if file = root.glob('{.,}#{DIRECTORY}/plugins{,.rb}').first
    require file
  else
    self.defaults = {}
  end
end
size() click to toggle source
# File lib/detroit/toolchain/config.rb, line 157
def size
  workers.size
end