Class: Attributor::Flatpack::ConfigDSLCompiler

Inherits:
HashDSLCompiler
  • Object
show all
Defined in:
lib/attributor/flatpack/config_dsl_compiler.rb

Instance Method Summary collapse

Instance Method Details

#key(name, attr_type = nil, **opts, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/attributor/flatpack/config_dsl_compiler.rb', line 4

def key(name, attr_type = nil, **opts, &block)
  native_key = options.fetch(:key_type, Attributor::Object).native_type
  unless name.is_a?(native_key)
    raise ArgumentError, "Invalid key: #{name.inspect}, " \
                         "must be instance of #{native_key}"
  end
  attr_type = Attributor::Flatpack::Config if attr_type.nil? && block
  target.keys[name] = define(name, attr_type, **opts, &block)
end