Class: TapDance::DSL
- Inherits:
-
Object
- Object
- TapDance::DSL
- Defined in:
- lib/tap_dance/dsl.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Class Method Summary collapse
Instance Method Summary collapse
- #brew(name, version = nil, opts = nil) ⇒ Object
- #eval_brewfile(brewfile, contents = nil) ⇒ Object
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
-
#tap(name, url, opts = {}) ⇒ Object
DSL commands.
Constructor Details
#initialize ⇒ DSL
Returns a new instance of DSL.
17 18 19 20 21 22 |
# File 'lib/tap_dance/dsl.rb', line 17 def initialize @groups = [] # Arg/filter groups @tap = nil # Current tap scope @definition = Definition.new end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
9 10 11 |
# File 'lib/tap_dance/dsl.rb', line 9 def definition @definition end |
Class Method Details
.evaluate(brewfile, lockfile = nil, unlock = nil) ⇒ Object
11 12 13 14 15 |
# File 'lib/tap_dance/dsl.rb', line 11 def self.evaluate(brewfile, lockfile=nil, unlock=nil) builder = new builder.eval_brewfile(brewfile) builder.definition end |
Instance Method Details
#brew(name, version = nil, opts = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tap_dance/dsl.rb', line 50 def brew(name, version=nil, opts=nil) # Was version omitted? if opts.nil? && version.is_a?(Hash) opts = version version = nil end opts ||= {} @definition.brew name, version, { :tap => @tap }.merge(opts) end |
#eval_brewfile(brewfile, contents = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tap_dance/dsl.rb', line 24 def eval_brewfile(brewfile, contents = nil) contents ||= File.read File.(brewfile.to_s) instance_eval contents, brewfile.to_s, 1 rescue SyntaxError => e bt = e..split("\n")[1..-1] raise BrewfileError, ["Brewfile syntax error:", *bt].join("\n") rescue ScriptError, RegexpError, NameError, ArgumentError => e e.backtrace[0] = "#{e.backtrace[0]}: #{e.} (#{e.class})" TapDance.ui.warn e.backtrace.join("\n ") raise BrewfileError, "There was an error in your Brewfile," \ " and TapDance cannot continue." end |
#tap(name, url, opts = {}) ⇒ Object
DSL commands
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tap_dance/dsl.rb', line 38 def tap(name, url, opts={}) # Can't nest taps; doesn't make sense raise BrewfileError, "You cannot nest taps!" unless @tap.nil? old_tap = @tap @tap = @definition.tap name, url, opts yield if block_given? @tap = old_tap end |