class JSON::SchemaDsl::Renderers::Base

The abstract base renderer that provides common behaviour to all renderers like the depth-first-traversal and access to the scope. @abstract

Attributes

scope[R]

Public Class Methods

new(scope) click to toggle source

@param [Object] scope The scope used as a fallback for helper methods.

# File lib/json/schema_dsl/renderers/base.rb, line 13
def initialize(scope)
  @scope = scope
end

Public Instance Methods

traverse(entity) click to toggle source

@param [Hash] entity The entity-structure given as a tree.

This method will recursively visit each value in the structure until
all have been visited.

@return [Hash] The hash-tree with all values visited.

# File lib/json/schema_dsl/renderers/base.rb, line 21
def traverse(entity)
  entity.transform_values { |v| step(v) }
end

Protected Instance Methods

step(value) click to toggle source

@param [Object] value The value that should be visited. Behaves differently

for each renderer, since #visit holds the core logic of each.

@return [Object] The visited object.

# File lib/json/schema_dsl/renderers/base.rb, line 30
def step(value)
  case value
  when ::Array
    value.first.is_a?(Hash) ? value.map { |v| visit(v) } : value
  when Hash then visit(value)
  else value
  end
end