Class: Escort::Setup::Dsl::Options
- Inherits:
-
Object
- Object
- Escort::Setup::Dsl::Options
- Defined in:
- lib/escort/setup/dsl/options.rb
Class Method Summary collapse
Instance Method Summary collapse
- #conflict(*opts) ⇒ Object
- #dependency(option_name, opts = {}) ⇒ Object
-
#initialize(command_name = :global) ⇒ Options
constructor
A new instance of Options.
- #opt(name, desc = "", opts = {}) ⇒ Object
- #validate(name, description, &block) ⇒ Object
Constructor Details
#initialize(command_name = :global) ⇒ Options
Returns a new instance of Options.
13 14 15 16 17 18 19 |
# File 'lib/escort/setup/dsl/options.rb', line 13 def initialize(command_name = :global) @command_name = command_name @options = {} @dependencies = {} @conflicts = {} @validations = {} end |
Class Method Details
.options(command_name, instance, &block) ⇒ Object
6 7 8 9 10 |
# File 'lib/escort/setup/dsl/options.rb', line 6 def (command_name, instance, &block) block.call(instance) if block_given? rescue => e raise Escort::ClientError.new("Problem with syntax of #{instance.instance_variable_get(:"@command_name")} options block", e) end |
Instance Method Details
#conflict(*opts) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/escort/setup/dsl/options.rb', line 42 def conflict(*opts) opts.each do |opt| conflicts_for_opt = opts.reject{|value| value == opt} @conflicts[opt] ||= [] @conflicts[opt] += conflicts_for_opt @conflicts[opt].uniq! end end |
#dependency(option_name, opts = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/escort/setup/dsl/options.rb', line 33 def dependency(option_name, opts = {}) ensure_dependency_specification_syntax(opts) @dependencies[option_name] ||= [] rules_as_array(opts).each do |rule| ensure_no_self_dependency(option_name, rule) @dependencies[option_name] << rule end end |
#opt(name, desc = "", opts = {}) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/escort/setup/dsl/options.rb', line 21 def opt(name, desc="", opts={}) opts[:desc] ||= desc @options[name] ||= opts dependency(name, :on => opts[:depends_on]) if opts[:depends_on] conflict(*[name, opts[:conflicts_with]].flatten) if opts[:conflicts_with] end |
#validate(name, description, &block) ⇒ Object
28 29 30 31 |
# File 'lib/escort/setup/dsl/options.rb', line 28 def validate(name, description, &block) @validations[name] ||= [] @validations[name] << {:desc => description, :block => block} end |