Class: Dry::Concrete::Value

Inherits:
Dry::Concrete show all
Defined in:
lib/dry/concrete/value.rb

Class Method Summary collapse

Methods inherited from Dry::Concrete

alias_fields, attribute, attribute?, build_type_from, initializer

Class Method Details

.new(value, *other, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dry/concrete/value.rb', line 6

def self.new(value, *other, &block)
  case value
  in Hash => attributes then super(attributes, *other, &block)
  in Dry::Struct => instance then instance
  else
    case attribute_names
    in [] then raise ArgumentError, "[#{self}] has no attributes, one is required"
    in [key] then super({ key => value }, *other, &block)
    else
      raise ArgumentError, "[#{self}] has more than one attribute: #{attribute_names.join(', ')}"
    end
  end
end