Sha256: be08c126abe633784bc6b60dc53e78c64302c73150b5592cbe939e804c8ce9ba
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
require "active_support" require "active_support/core_ext" require "yaml_ext" require "schema_serializer/definition" require "schema_serializer/schema" require "schema_serializer/serializable" require "schema_serializer/errors" require "schema_serializer/version" require "schema_serializer/railtie" if defined?(Rails) class SchemaSerializer attr_reader :object, :options class << self attr_reader :definition 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 self.definition = doc end def definition=(define) @definition = define.is_a?(SchemaSerializer::Definition) ? define : SchemaSerializer::Definition.new(define) end end def initialize(object, options = {}) @object = object @options = options end def as_json(_options = nil) schema.serialize(self) end def schema ::SchemaSerializer.definition.schema(schema_name) end def schema_name return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer object.class.name end private def method_missing(name, *args, &block) super unless object.respond_to?(name) object.public_send(name, *args, &block) end def respond_to_missing?(name, _include_private = false) object.respond_to?(name) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
schema_serializer-0.2.2 | lib/schema_serializer.rb |
schema_serializer-0.2.1 | lib/schema_serializer.rb |