Class: Detroit::Toolchain::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/detroit/toolchain/config.rb

Overview

Detroit configuration.

TODO: Greatly simplify this, to support

Constant Summary collapse

DIRECTORY =

Configuration directory name (most likely a hidden "dot" directory).

"detroit"
FILE_EXTENSION =

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

"assembly"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, assembly_files = nil) ⇒ Config

Returns a new instance of Config.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

Instance Attribute Details

#assembliesArray<String> (readonly)

The list of a project's assembly files.

Returns:



26
27
28
# File 'lib/detroit/toolchain/config.rb', line 26

def assemblies
  @assemblies
end

#defaultsHash

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

Returns:

  • (Hash)

    default settings



38
39
40
# File 'lib/detroit/toolchain/config.rb', line 38

def defaults
  @defaults
end

#rootObject (readonly)

TODO: Should this be project instead?



21
22
23
# File 'lib/detroit/toolchain/config.rb', line 21

def root
  @root
end

#workersHash (readonly)

Worker configurations from Assembly or *.assembly files.

Returns:



31
32
33
# File 'lib/detroit/toolchain/config.rb', line 31

def workers
  @workers
end

Instance Method Details

#assembly_filenamesObject

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.



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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

#each(&block) ⇒ Object



152
153
154
# File 'lib/detroit/toolchain/config.rb', line 152

def each(&block)
  workers.each(&block)
end

#load_assembliesObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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) ⇒ Object



117
118
119
120
121
# 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_defaultsObject

Load defaults from .detroit/defaults.yml.



86
87
88
89
90
91
92
# 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) ⇒ Object

Load a plugin.



63
64
65
66
67
68
69
70
71
72
73
74
# 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_pluginsObject

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



77
78
79
80
81
82
83
# 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

#sizeObject



157
158
159
# File 'lib/detroit/toolchain/config.rb', line 157

def size
  workers.size
end