Class: SchemaSerializer
- Inherits:
-
Object
- Object
- SchemaSerializer
- Defined in:
- lib/schema_serializer.rb,
lib/schema_serializer/errors.rb,
lib/schema_serializer/schema.rb,
lib/schema_serializer/railtie.rb,
lib/schema_serializer/version.rb,
lib/schema_serializer/definition.rb,
lib/schema_serializer/serializable.rb
Defined Under Namespace
Modules: Generators, Serializable Classes: BaseError, Definition, Railtie, RequiredNotDefined, Schema, SchemaNotFound
Constant Summary collapse
- VERSION =
"0.2.2".freeze
Class Attribute Summary collapse
-
.definition ⇒ Object
Returns the value of attribute definition.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(_options = nil) ⇒ Object
-
#initialize(object, options = {}) ⇒ SchemaSerializer
constructor
A new instance of SchemaSerializer.
- #schema ⇒ Object
- #schema_name ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ SchemaSerializer
32 33 34 35 |
# File 'lib/schema_serializer.rb', line 32 def initialize(object, = {}) @object = object @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
53 54 55 56 57 |
# File 'lib/schema_serializer.rb', line 53 def method_missing(name, *args, &block) super unless object.respond_to?(name) object.public_send(name, *args, &block) end |
Class Attribute Details
.definition ⇒ Object
Returns the value of attribute definition.
16 17 18 |
# File 'lib/schema_serializer.rb', line 16 def definition @definition end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
13 14 15 |
# File 'lib/schema_serializer.rb', line 13 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/schema_serializer.rb', line 13 def @options end |
Class Method Details
.load_definition(path) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/schema_serializer.rb', line 18 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 |
Instance Method Details
#as_json(_options = nil) ⇒ Object
37 38 39 |
# File 'lib/schema_serializer.rb', line 37 def as_json( = nil) schema.serialize(self) end |
#schema ⇒ Object
41 42 43 |
# File 'lib/schema_serializer.rb', line 41 def schema ::SchemaSerializer.definition.schema(schema_name) end |
#schema_name ⇒ Object
45 46 47 48 49 |
# File 'lib/schema_serializer.rb', line 45 def schema_name return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer object.class.name end |