Class: Datacaster::JsonSchemaNode

Inherits:
Base
  • Object
show all
Defined in:
lib/datacaster/json_schema_node.rb

Instance Method Summary collapse

Methods included from Mixin

#&, #*, #call, #call_with_runtime, #cast_errors, #i18n_key, #i18n_map_keys, #i18n_scope, #i18n_vars, #json_schema, #json_schema_attributes, #then, #with_context, #with_object_context, #with_runtime, #|

Constructor Details

#initialize(base, schema_attributes = {}, &block) ⇒ JsonSchemaNode

Returns a new instance of JsonSchemaNode.



3
4
5
6
7
# File 'lib/datacaster/json_schema_node.rb', line 3

def initialize(base, schema_attributes = {}, &block)
  @base = base
  @schema_attributes = schema_attributes.transform_keys(&:to_s)
  @block = block
end

Instance Method Details

#cast(object, runtime:) ⇒ Object



9
10
11
# File 'lib/datacaster/json_schema_node.rb', line 9

def cast(object, runtime:)
  @base.cast(object, runtime: runtime)
end

#inspectObject



24
25
26
# File 'lib/datacaster/json_schema_node.rb', line 24

def inspect
  "#<#{self.class.name} base: #{@base.inspect}>"
end

#to_json_schemaObject



13
14
15
16
17
18
# File 'lib/datacaster/json_schema_node.rb', line 13

def to_json_schema
  result = @base.to_json_schema
  result = result.apply(@schema_attributes)
  result = @block.(result) if @block
  result
end

#to_json_schema_attributesObject



20
21
22
# File 'lib/datacaster/json_schema_node.rb', line 20

def to_json_schema_attributes
  @base.to_json_schema_attributes
end