Class: Scripted::Configuration
- Inherits:
-
Object
- Object
- Scripted::Configuration
- Defined in:
- lib/scripted/configuration.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
Instance Method Summary collapse
- #absolute_config_files ⇒ Object
- #color? ⇒ Boolean
- #config_file(*file_names) ⇒ Object
- #config_files ⇒ Object
- #evaluate(*args, &block) ⇒ Object
- #formatter(name, options = {}) ⇒ Object
- #formatters ⇒ Object
-
#group(name, &block) ⇒ Object
Defines a group.
- #groups ⇒ Object
- #load_file(file_name) ⇒ Object
- #load_files ⇒ Object
- #out(out) ⇒ Object
-
#parallel(&block) ⇒ Object
Makes a parallel block inside the ‘:default` group.
- #raise_config_file_error(file_name) ⇒ Object
-
#run(name, &block) ⇒ Object
(also: #:`)
Defines a command in the ‘:default` group.
- #with_default_config_file! ⇒ Object
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
13 14 15 |
# File 'lib/scripted/configuration.rb', line 13 def color @color end |
Instance Method Details
#absolute_config_files ⇒ Object
61 62 63 |
# File 'lib/scripted/configuration.rb', line 61 def absolute_config_files config_files.map { |file_name| File.(file_name) }.uniq end |
#color? ⇒ Boolean
35 36 37 |
# File 'lib/scripted/configuration.rb', line 35 def color? color.nil? ? true : color end |
#config_file(*file_names) ⇒ Object
51 52 53 54 55 |
# File 'lib/scripted/configuration.rb', line 51 def config_file(*file_names) file_names.each do |file_name| config_files << file_name end end |
#config_files ⇒ Object
57 58 59 |
# File 'lib/scripted/configuration.rb', line 57 def config_files @config_files ||= [] end |
#evaluate(*args, &block) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/scripted/configuration.rb', line 89 def evaluate(*args, &block) instance_eval(*args, &block) rescue Exception => error my_error = ConfigurationSyntaxError.new("#{error.} (#{error.class})") my_error.set_backtrace error.backtrace raise my_error end |
#formatter(name, options = {}) ⇒ Object
31 32 33 |
# File 'lib/scripted/configuration.rb', line 31 def formatter(name, = {}) formatters << .merge(:name => name) end |
#formatters ⇒ Object
47 48 49 |
# File 'lib/scripted/configuration.rb', line 47 def formatters @formatters ||= [] end |
#group(name, &block) ⇒ Object
Defines a group
16 17 18 |
# File 'lib/scripted/configuration.rb', line 16 def group(name, &block) groups[name].define(&block) end |
#groups ⇒ Object
65 66 67 |
# File 'lib/scripted/configuration.rb', line 65 def groups @groups ||= Hash.new { |hash, key| hash[key] = Group.new(key) } end |
#load_file(file_name) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/scripted/configuration.rb', line 82 def load_file(file_name) source = File.open(file_name, 'r:utf-8').read evaluate source, file_name, 1 rescue Errno::ENOENT => error raise_config_file_error(file_name) end |
#load_files ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/scripted/configuration.rb', line 73 def load_files absolute_config_files.each do |file_name| load_file(file_name) end if groups.empty? raise_config_file_error("scripted.rb") end end |
#out(out) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/scripted/configuration.rb', line 39 def out(out) if formatters.any? formatters.last[:out] = out else fail NoFormatterForOutput, "You must first specify a formatter to use this option" end end |
#parallel(&block) ⇒ Object
Makes a parallel block inside the ‘:default` group.
27 28 29 |
# File 'lib/scripted/configuration.rb', line 27 def parallel(&block) groups[:default].define { parallel(&block) } end |
#raise_config_file_error(file_name) ⇒ Object
97 98 99 |
# File 'lib/scripted/configuration.rb', line 97 def raise_config_file_error(file_name) raise ConfigFileNotFound, "No such file -- #{File.(file_name)}\nEither create a file called 'scripted.rb', or specify another file to load" end |
#run(name, &block) ⇒ Object Also known as: :`
Defines a command in the ‘:default` group.
21 22 23 |
# File 'lib/scripted/configuration.rb', line 21 def run(name, &block) groups[:default].define { run(name, &block) } end |
#with_default_config_file! ⇒ Object
69 70 71 |
# File 'lib/scripted/configuration.rb', line 69 def with_default_config_file! config_file "scripted.rb" if config_files.empty? && File.exist?("scripted.rb") end |