Class: Dry::Value

Inherits:
Struct
  • Object
show all
Defined in:
lib/dry/value.rb

Class Method Summary collapse

Class Method Details

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



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

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