Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make MacOS.language less opinionated and add language stanza. #906

Merged
merged 15 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add language stanza to cask DSL.
  • Loading branch information
reitermarkus committed Oct 3, 2016
commit f52116cd2622eff3ef1611e059bab8b96163a596
26 changes: 26 additions & 0 deletions Library/Homebrew/cask/lib/hbc/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class DSL
:depends_on,
:gpg,
:homepage,
:language,
:license,
:name,
:sha256,
Expand Down Expand Up @@ -98,6 +99,31 @@ def homepage(homepage = nil)
@homepage ||= homepage
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
@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
end
end

def url(*args, &block)
url_given = !args.empty? || block_given?
return @url unless url_given
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/lib/hbc/dsl/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(cask, command = SystemCommand)
@command = command
end

def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir
def_delegators :@cask, :token, :version, :caskroom_path, :staged_path, :appdir, :language

def system_command(executable, options = {})
@command.run!(executable, options)
Expand Down