brew/Library/Homebrew/cask/lib/hbc/artifact/abstract_flight_block.rb
Mike McQuaid 80d75bc0d8
Homebrew/.rubocop: tweak rules.
Adjust the rules based on the current codebase. Remove various enable,
disables and default values that are unnecessary. Add more comments
explaining why. Make minor changes needed to enable a few more rules.
2018-09-02 20:15:09 +01:00

47 lines
1.1 KiB
Ruby

require "hbc/artifact/abstract_artifact"
module Hbc
module Artifact
class AbstractFlightBlock < AbstractArtifact
def self.dsl_key
super.to_s.sub(/_block$/, "").to_sym
end
def self.uninstall_dsl_key
dsl_key.to_s.prepend("uninstall_").to_sym
end
attr_reader :directives
def initialize(cask, **directives)
super(cask)
@directives = directives
end
def install_phase(**)
abstract_phase(self.class.dsl_key)
end
def uninstall_phase(**)
abstract_phase(self.class.uninstall_dsl_key)
end
private
def class_for_dsl_key(dsl_key)
namespace = self.class.name.to_s.sub(/::.*::.*$/, "")
self.class.const_get("#{namespace}::DSL::#{dsl_key.to_s.split("_").map(&:capitalize).join}")
end
def abstract_phase(dsl_key)
return if (block = directives[dsl_key]).nil?
class_for_dsl_key(dsl_key).new(cask).instance_eval(&block)
end
def summarize
directives.keys.map(&:to_s).join(", ")
end
end
end
end