Refactor DependsOn with DelegateClass.
This commit is contained in:
parent
e300713f25
commit
bd0b763292
@ -2,7 +2,7 @@ require "rubygems"
|
|||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
class DSL
|
class DSL
|
||||||
class DependsOn
|
class DependsOn < DelegateClass(Hash)
|
||||||
VALID_KEYS = Set.new [
|
VALID_KEYS = Set.new [
|
||||||
:formula,
|
:formula,
|
||||||
:cask,
|
:cask,
|
||||||
@ -19,19 +19,18 @@ module Hbc
|
|||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
attr_accessor :java
|
attr_accessor :java
|
||||||
attr_accessor :pairs
|
|
||||||
attr_reader :arch, :cask, :formula, :macos, :x11
|
attr_reader :arch, :cask, :formula, :macos, :x11
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@pairs ||= {}
|
super({})
|
||||||
@cask ||= []
|
@cask ||= []
|
||||||
@formula ||= []
|
@formula ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def load(pairs = {})
|
def load(**pairs)
|
||||||
pairs.each do |key, value|
|
pairs.each do |key, value|
|
||||||
raise "invalid depends_on key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
|
raise "invalid depends_on key: '#{key.inspect}'" unless VALID_KEYS.include?(key)
|
||||||
@pairs[key] = send(:"#{key}=", *value)
|
self[key] = send(:"#{key}=", *value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,14 +89,6 @@ module Hbc
|
|||||||
raise "invalid 'depends_on x11' value: #{arg.inspect}" unless [true, false].include?(arg)
|
raise "invalid 'depends_on x11' value: #{arg.inspect}" unless [true, false].include?(arg)
|
||||||
@x11 = arg
|
@x11 = arg
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_yaml
|
|
||||||
@pairs.to_yaml
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_s
|
|
||||||
@pairs.inspect
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user