Class: Dry::Types::Definition

Inherits:
Object
  • Object
show all
Includes:
Builder
Defined in:
lib/dry/types/definition.rb,
lib/dry/types/definition/hash.rb,
lib/dry/types/definition/array.rb

Direct Known Subclasses

Constructor, Array, Hash

Defined Under Namespace

Classes: Array, Hash

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Builder

#constrained, #constructor, #default, #enum, #optional, #safe, #|

Constructor Details

#initialize(primitive, options = {}) ⇒ Definition

Returns a new instance of Definition.



23
24
25
26
# File 'lib/dry/types/definition.rb', line 23

def initialize(primitive, options = {})
  @primitive = primitive
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/dry/types/definition.rb', line 9

def options
  @options
end

#primitiveObject (readonly)

Returns the value of attribute primitive.



11
12
13
# File 'lib/dry/types/definition.rb', line 11

def primitive
  @primitive
end

Class Method Details

.[](primitive) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/dry/types/definition.rb', line 13

def self.[](primitive)
  if primitive == ::Array
    Definition::Array
  elsif primitive == ::Hash
    Definition::Hash
  else
    self
  end
end

Instance Method Details

#call(input) ⇒ Object Also known as: []



36
37
38
# File 'lib/dry/types/definition.rb', line 36

def call(input)
  input
end

#nameObject



32
33
34
# File 'lib/dry/types/definition.rb', line 32

def name
  primitive.name
end

#try(input) ⇒ Object



41
42
43
# File 'lib/dry/types/definition.rb', line 41

def try(input)
  call(input)
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/dry/types/definition.rb', line 45

def valid?(input)
  input.is_a?(primitive)
end

#with(new_options) ⇒ Object



28
29
30
# File 'lib/dry/types/definition.rb', line 28

def with(new_options)
  self.class.new(primitive, options.merge(new_options))
end