diff options
| author | Markus Reiter | 2016-09-18 04:15:28 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-10-03 02:34:52 +0200 |
| commit | 65fdfefc99e2308a406e57eb55cd2e32f107717f (patch) | |
| tree | a9cf7618f1ec25abf1c31c8747ee4d50e6a2da6a | |
| parent | f52116cd2622eff3ef1611e059bab8b96163a596 (diff) | |
| download | brew-65fdfefc99e2308a406e57eb55cd2e32f107717f.tar.bz2 | |
Add `language_eval` method.
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cask.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl.rb | 17 |
2 files changed, 13 insertions, 9 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 756b05b83..1e2056efc 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -11,7 +11,10 @@ module Hbc @token = token @sourcefile_path = sourcefile_path @dsl = dsl || DSL.new(@token) - @dsl.instance_eval(&block) if block_given? + if block_given? + @dsl.instance_eval(&block) + @dsl.language_eval + end end DSL::DSL_METHODS.each do |method_name| diff --git a/Library/Homebrew/cask/lib/hbc/dsl.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb index 69ade9a86..a1b3280e6 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl.rb @@ -100,30 +100,31 @@ module Hbc end def language(*args, &block) - @language ||= {} - if !args.empty? && block_given? args.each do |arg| MacOS.languages.each_with_index do |l, index| string_or_regex = arg == :default ? %r{^en} : arg next unless l.match(string_or_regex) - next unless @language[:level].nil? || @language[:level] > index + next unless @language.nil? || @language[:level].nil? || @language[:level] > index @language = { block: block, level: index, } end end - - if args.include?(:default) - # :default has to be the last language block in order to assign return value of the selected `language` block to `@language` - @language = @language[:block].call - end else + language_eval @language end end + + def language_eval + if @language.is_a?(Hash) && @language.key?(:block) + @language = @language[:block].call + end + end + def url(*args, &block) url_given = !args.empty? || block_given? return @url unless url_given |
