brew/Library/Homebrew/cask/dsl/container.rb

35 lines
707 B
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
require "unpack_strategy"
2017-04-21 13:43:13 +02:00
2018-09-06 08:29:14 +02:00
module Cask
2016-09-24 13:52:43 +02:00
class DSL
2020-08-24 23:09:43 +02:00
# Class corresponding to the `container` stanza.
2016-09-24 13:52:43 +02:00
class Container
attr_accessor :nested, :type
2016-08-18 22:11:42 +03:00
def initialize(nested: nil, type: nil)
@nested = nested
@type = type
2017-04-21 13:43:13 +02:00
return if type.nil?
return unless UnpackStrategy.from_type(type).nil?
2018-09-17 02:45:00 +02:00
2017-04-21 13:43:13 +02:00
raise "invalid container type: #{type.inspect}"
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
def pairs
instance_variables.to_h { |ivar| [ivar[1..].to_sym, instance_variable_get(ivar)] }.compact
end
2016-09-24 13:52:43 +02:00
def to_yaml
pairs.to_yaml
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
2024-04-26 14:04:55 +02:00
sig { returns(String) }
def to_s = pairs.inspect
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
end