diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 756b05b83fcb7a274ed6824d1857b3669a0de59a..1e2056efc705eba0bd945ff40b20d39590714c1f 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 69ade9a861735905d71da5a7e713cdb93dcf4afe..a1b3280e66048a10962dbb836b8fd773a08476f7 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