Class: Definition::Types::Keys

Inherits:
Base
  • Object
show all
Includes:
Dsl
Defined in:
lib/definition/types/keys.rb

Defined Under Namespace

Modules: Dsl Classes: Conformer

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #name

Instance Method Summary collapse

Methods included from Dsl

#include, #option, #optional, #required

Methods inherited from Base

#error_renderer, #explain

Constructor Details

#initialize(name, req: {}, opt: {}, defaults: {}, options: {}) ⇒ Keys

Returns a new instance of Keys.



63
64
65
66
67
68
69
# File 'lib/definition/types/keys.rb', line 63

def initialize(name, req: {}, opt: {}, defaults: {}, options: {})
  super(name)
  self.required_definitions = req
  self.optional_definitions = opt
  self.defaults = defaults
  self.ignore_extra_keys = options.fetch(:ignore_extra_keys, false)
end

Instance Attribute Details

#defaultsObject

Returns the value of attribute defaults.



61
62
63
# File 'lib/definition/types/keys.rb', line 61

def defaults
  @defaults
end

#ignore_extra_keysObject

Returns the value of attribute ignore_extra_keys.



61
62
63
# File 'lib/definition/types/keys.rb', line 61

def ignore_extra_keys
  @ignore_extra_keys
end

#optional_definitionsObject

Returns the value of attribute optional_definitions.



61
62
63
# File 'lib/definition/types/keys.rb', line 61

def optional_definitions
  @optional_definitions
end

#required_definitionsObject

Returns the value of attribute required_definitions.



61
62
63
# File 'lib/definition/types/keys.rb', line 61

def required_definitions
  @required_definitions
end

Instance Method Details

#conform(value) ⇒ Object



71
72
73
# File 'lib/definition/types/keys.rb', line 71

def conform(value)
  Conformer.new(self, value).conform
end

#keysObject



75
76
77
# File 'lib/definition/types/keys.rb', line 75

def keys
  required_definitions.keys + optional_definitions.keys
end