Module: EasyParams::Types::Struct

Included in:
Base
Defined in:
lib/easy_params/types/struct.rb

Overview

base interface for struct type

Instance Method Summary collapse

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/easy_params/types/struct.rb', line 7

def array?
  false
end

#coerce(value) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/easy_params/types/struct.rb', line 29

def coerce(value)
  return if value.nil? && @default.nil?

  input = value || @default
  input = @normalize_proc.call(input) if @normalize_proc
  return self.class.new(input) if input.is_a?(Hash)

  self.class.new(input)
end

#default(value) ⇒ Object



19
20
21
22
# File 'lib/easy_params/types/struct.rb', line 19

def default(value)
  self.default = value
  self
end

#normalize(&block) ⇒ Object



24
25
26
27
# File 'lib/easy_params/types/struct.rb', line 24

def normalize(&block)
  @normalize_proc = block
  self
end

#normalize_procObject



15
16
17
# File 'lib/easy_params/types/struct.rb', line 15

def normalize_proc
  @normalize_proc
end

#read_defaultObject



11
12
13
# File 'lib/easy_params/types/struct.rb', line 11

def read_default
  @default
end