class SchemaSerializer

Constants

VERSION

Attributes

definition[R]
object[R]
options[R]

Public Class Methods

config() click to toggle source
# File lib/schema_serializer.rb, line 40
def config
  @config ||= Configuration.new
end
definition=(define) click to toggle source
# File lib/schema_serializer.rb, line 36
def definition=(define)
  @definition = define.is_a?(SchemaSerializer::Definition) ? define : SchemaSerializer::Definition.new(define)
end
load_definition(path) click to toggle source
# File lib/schema_serializer.rb, line 20
def load_definition(path)
  doc = YamlExt.load(path)
  if doc.has_key?("openapi") && Gem::Version.new(doc.fetch("openapi")) >= Gem::Version.new("3.0.0")
    doc = doc.fetch("components").fetch("schemas")
  end

  @document_path = path
  self.definition = doc
end
new(object, options = {}) click to toggle source
# File lib/schema_serializer.rb, line 45
def initialize(object, options = {})
  @object = object
  @options = options
end
reload!() click to toggle source
# File lib/schema_serializer.rb, line 30
def reload!
  raise ReloadError, "Load config using .load_definition" if @document_path.nil?

  load_definition(@document_path)
end

Public Instance Methods

as_json(_options = nil) click to toggle source
# File lib/schema_serializer.rb, line 50
def as_json(_options = nil)
  schema.serialize(self)
end
schema() click to toggle source
# File lib/schema_serializer.rb, line 54
def schema
  ::SchemaSerializer.definition.schema(schema_name)
end
schema_name() click to toggle source
# File lib/schema_serializer.rb, line 58
def schema_name
  return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer

  object.class.name
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/schema_serializer.rb, line 66
def method_missing(name, *args, &block)
  super unless object.respond_to?(name)

  object.public_send(name, *args, &block)
end
respond_to_missing?(name, _include_private = false) click to toggle source
Calls superclass method
# File lib/schema_serializer.rb, line 72
def respond_to_missing?(name, _include_private = false)
  super
  object.respond_to?(name)
end