Class: Detroit::Toolchain::Config
- 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
-
#assemblies ⇒ Array<String>
readonly
The list of a project's assembly files.
-
#defaults ⇒ Hash
Worker defaults.
-
#root ⇒ Object
readonly
TODO: Should this be project instead?.
-
#workers ⇒ Hash
readonly
Worker configurations from Assembly or *.assembly files.
Instance Method Summary collapse
-
#assembly_filenames ⇒ Object
If a
Assemblyor.assemblyfile exists, then it is returned. - #each(&block) ⇒ Object
-
#initialize(root, assembly_files = nil) ⇒ Config
constructor
A new instance of Config.
- #load_assemblies ⇒ Object
- #load_assembly_file(file) ⇒ Object
-
#load_defaults ⇒ Object
Load defaults from
.detroit/defaults.yml. -
#load_plugin(name) ⇒ Object
Load a plugin.
-
#load_plugins ⇒ Object
Pre-load plugins using
.detroit/plugins.rb. - #size ⇒ Object
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
#assemblies ⇒ Array<String> (readonly)
The list of a project's assembly files.
26 27 28 |
# File 'lib/detroit/toolchain/config.rb', line 26 def assemblies @assemblies end |
#defaults ⇒ Hash
Worker defaults. This is a mapping of worker names to default settings. Very useful for when using the same worker more than once.
38 39 40 |
# File 'lib/detroit/toolchain/config.rb', line 38 def defaults @defaults end |
#root ⇒ Object (readonly)
TODO: Should this be project instead?
21 22 23 |
# File 'lib/detroit/toolchain/config.rb', line 21 def root @root end |
#workers ⇒ Hash (readonly)
Worker configurations from Assembly or *.assembly files.
31 32 33 |
# File 'lib/detroit/toolchain/config.rb', line 31 def workers @workers end |
Instance Method Details
#assembly_filenames ⇒ Object
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_assemblies ⇒ Object
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_defaults ⇒ Object
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..capitalize}" $stderr.puts " Perhaps `gem install detroit-#{name}`?" exit -1 end name # true ? ) end |
#load_plugins ⇒ Object
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 |
#size ⇒ Object
157 158 159 |
# File 'lib/detroit/toolchain/config.rb', line 157 def size workers.size end |