diff options
| author | Mike McQuaid | 2016-09-24 20:48:03 +0100 | 
|---|---|---|
| committer | Mike McQuaid | 2016-09-24 20:48:03 +0100 | 
| commit | e767fd3df9d179fca0445cc0bc0fdc061ad857d6 (patch) | |
| tree | 93e9db33313b36eebe7d7fb3aedf0f92cc2c3918 /Library/Homebrew/cask/lib/hbc/artifact/moved.rb | |
| parent | 7fc241765e3654718235791c32e5638bf7f8e15a (diff) | |
| parent | 232078df57418004bb9bf7abef877e734fcf7005 (diff) | |
| download | brew-e767fd3df9d179fca0445cc0bc0fdc061ad857d6.tar.bz2 | |
Merge branch 'master' into mkdir_with_intermediates
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/artifact/moved.rb')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/moved.rb | 148 | 
1 files changed, 76 insertions, 72 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 8565ab836..6095887e3 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -1,88 +1,92 @@  require "hbc/artifact/relocated" -class Hbc::Artifact::Moved < Hbc::Artifact::Relocated -  def self.english_description -    "#{artifact_english_name}s" -  end +module Hbc +  module Artifact +    class Moved < Relocated +      def self.english_description +        "#{artifact_english_name}s" +      end -  def install_phase -    each_artifact do |artifact| -      load_specification(artifact) -      next unless preflight_checks -      delete if Hbc::Utils.path_occupied?(target) && force -      move -    end -  end +      def install_phase +        each_artifact do |artifact| +          load_specification(artifact) +          next unless preflight_checks +          delete if Utils.path_occupied?(target) && force +          move +        end +      end -  def uninstall_phase -    each_artifact do |artifact| -      load_specification(artifact) -      next unless File.exist?(target) -      delete -    end -  end +      def uninstall_phase +        each_artifact do |artifact| +          load_specification(artifact) +          next unless File.exist?(target) +          delete +        end +      end -  private +      private -  def each_artifact -    # the sort is for predictability between Ruby versions -    @cask.artifacts[self.class.artifact_dsl_key].sort.each do |artifact| -      yield artifact -    end -  end +      def each_artifact +        # the sort is for predictability between Ruby versions +        @cask.artifacts[self.class.artifact_dsl_key].sort.each do |artifact| +          yield artifact +        end +      end -  def move -    ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" -    target.dirname.mkpath -    FileUtils.move(source, target) -    add_altname_metadata target, source.basename.to_s -  end +      def move +        ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" +        target.dirname.mkpath +        FileUtils.move(source, target) +        add_altname_metadata target, source.basename.to_s +      end -  def preflight_checks -    if Hbc::Utils.path_occupied?(target) -      if force -        ohai(warning_target_exists { |s| s << "overwriting." }) -      else -        ohai(warning_target_exists { |s| s << "not moving." }) -        return false +      def preflight_checks +        if Utils.path_occupied?(target) +          if force +            ohai(warning_target_exists { |s| s << "overwriting." }) +          else +            ohai(warning_target_exists { |s| s << "not moving." }) +            return false +          end +        end +        unless source.exist? +          message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'" +          raise CaskError, message +        end +        true        end -    end -    unless source.exist? -      message = "It seems the #{self.class.artifact_english_name} source is not there: '#{source}'" -      raise Hbc::CaskError, message -    end -    true -  end -  def warning_target_exists -    message_parts = [ -                      "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'", -                    ] -    yield(message_parts) if block_given? -    message_parts.join("; ") -  end +      def warning_target_exists +        message_parts = [ +                          "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'", +                        ] +        yield(message_parts) if block_given? +        message_parts.join("; ") +      end -  def delete -    ohai "Removing #{self.class.artifact_english_name}: '#{target}'" -    if MacOS.undeletable?(target) -      raise Hbc::CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" -    elsif force -      Hbc::Utils.gain_permissions_remove(target, command: @command) -    else -      target.rmtree -    end -  end +      def delete +        ohai "Removing #{self.class.artifact_english_name}: '#{target}'" +        raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}" if MacOS.undeletable?(target) -  def summarize_artifact(artifact_spec) -    load_specification artifact_spec +        if force +          Utils.gain_permissions_remove(target, command: @command) +        else +          target.rmtree +        end +      end -    if target.exist? -      target_abv = " (#{target.abv})" -    else -      warning = "Missing #{self.class.artifact_english_name}" -      warning = "#{Tty.red}#{warning}#{Tty.reset}: " -    end +      def summarize_artifact(artifact_spec) +        load_specification artifact_spec -    "#{warning}#{printable_target}#{target_abv}" +        if target.exist? +          target_abv = " (#{target.abv})" +        else +          warning = "Missing #{self.class.artifact_english_name}" +          warning = "#{Tty.red}#{warning}#{Tty.reset}: " +        end + +        "#{warning}#{printable_target}#{target_abv}" +      end +    end    end  end  | 
