Class: Definition::Types::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/definition/types/base.rb

Direct Known Subclasses

And, Each, Include, Keys, Lambda, Nil, Or, Type

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, context: {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/definition/types/base.rb', line 12

def initialize(name, context: {})
  self.name = name
  self.context = context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/definition/types/base.rb', line 10

def context
  @context
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/definition/types/base.rb', line 10

def name
  @name
end

Instance Method Details

#conform(_value) ⇒ Object

Raises:

  • (NotImplementedError)


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

def conform(_value)
  raise NotImplementedError
end

#error_rendererObject



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

def error_renderer
  ErrorRenderers::Standard
end

#explain(value) ⇒ Object



17
18
19
20
21
22
# File 'lib/definition/types/base.rb', line 17

def explain(value)
  result = conform(value)
  return "value passes definition" if result.passed?

  result.error_message
end