Skip to content

Commit 65fdfef

Browse files
committed
Add language_eval method.
1 parent f52116c commit 65fdfef

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Library/Homebrew/cask/lib/hbc/cask.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def initialize(token, sourcefile_path: nil, dsl: nil, &block)
1111
@token = token
1212
@sourcefile_path = sourcefile_path
1313
@dsl = dsl || DSL.new(@token)
14-
@dsl.instance_eval(&block) if block_given?
14+
if block_given?
15+
@dsl.instance_eval(&block)
16+
@dsl.language_eval
17+
end
1518
end
1619

1720
DSL::DSL_METHODS.each do |method_name|

Library/Homebrew/cask/lib/hbc/dsl.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,31 @@ def homepage(homepage = nil)
100100
end
101101

102102
def language(*args, &block)
103-
@language ||= {}
104-
105103
if !args.empty? && block_given?
106104
args.each do |arg|
107105
MacOS.languages.each_with_index do |l, index|
108106
string_or_regex = arg == :default ? %r{^en} : arg
109107
next unless l.match(string_or_regex)
110-
next unless @language[:level].nil? || @language[:level] > index
108+
next unless @language.nil? || @language[:level].nil? || @language[:level] > index
111109
@language = {
112110
block: block,
113111
level: index,
114112
}
115113
end
116114
end
117-
118-
if args.include?(:default)
119-
# :default has to be the last language block in order to assign return value of the selected `language` block to `@language`
120-
@language = @language[:block].call
121-
end
122115
else
116+
language_eval
123117
@language
124118
end
125119
end
126120

121+
122+
def language_eval
123+
if @language.is_a?(Hash) && @language.key?(:block)
124+
@language = @language[:block].call
125+
end
126+
end
127+
127128
def url(*args, &block)
128129
url_given = !args.empty? || block_given?
129130
return @url unless url_given

0 commit comments

Comments
 (0)