Skip to content

Commit

Permalink
WIP forward-compatible DSL synonyms
Browse files Browse the repository at this point in the history
This makes the following stanzas available in the DSL as
synonyms to existing stanza, with no change to existing
functionality:
- pkg for `install`
- app for `link`
- suite for `link`
- preflight for `before_install`
- postflight for `before_uninstall`
- uninstall_preflight for `before_uninstall`
- uninstall_postflight for `after_uninstall`

References Homebrew#4688

This works, but is marked WIP because we are not in a hurry,
and because I intend to add tests.
  • Loading branch information
rolandwalker committed Jun 12, 2014
1 parent 3f9120e commit 8ab9bae
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,24 @@ def caveats(*string, &block)
end
end

# This hash is transitional. Each of these stanzas will
# ultimately either be removed or upgraded with its own
# unique semantics.
STANZA_ALIASES = {
:pkg => :install, # to remove
:app => :link, # to upgrade
:suite => :link, # to upgrade
:preflight => :before_install, # to remove
:postflight => :after_install, # to remove
:uninstall_preflight => :before_uninstall, # to remove
:uninstall_postflight => :after_uninstall, # to remove
}

def self.ordinary_artifact_types
@@ordinary_artifact_types ||= [
:link,
:app,
:suite,
:prefpane,
:qlplugin,
:font,
Expand All @@ -96,16 +111,18 @@ def self.ordinary_artifact_types
:binary,
:input_method,
:screen_saver,
:install,
:install, # deprecated
:pkg,
]
end

installable_artifact_types = ordinary_artifact_types
installable_artifact_types.push :caskroom_only

installable_artifact_types.each do |type|
resolved_type = STANZA_ALIASES.key?(type) ? STANZA_ALIASES[type] : type
define_method(type) do |*args|
artifacts[type] << args
artifacts[resolved_type] << args
end
end

Expand All @@ -121,15 +138,20 @@ def self.ordinary_artifact_types
end

ARTIFACT_BLOCK_TYPES = [
:after_install,
:after_uninstall,
:before_install,
:before_uninstall,
:after_install, # deprecated
:after_uninstall, # deprecated
:before_install, # deprecated
:before_uninstall, # deprecated
:preflight,
:postflight,
:uninstall_preflight,
:uninstall_postflight,
]

ARTIFACT_BLOCK_TYPES.each do |type|
resolved_type = STANZA_ALIASES.key?(type) ? STANZA_ALIASES[type] : type
define_method(type) do |&block|
artifacts[type] << block
artifacts[resolved_type] << block
end
end

Expand Down

0 comments on commit 8ab9bae

Please sign in to comment.