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.1.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.
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
Returns a new instance of SchemaSerializer.
27 28 29 |
# File 'lib/schema_serializer.rb', line 27 def initialize(object, = {}) @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
47 48 49 50 51 |
# File 'lib/schema_serializer.rb', line 47 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 |
Class Method Details
.load_definition(path) ⇒ Object
18 19 20 |
# File 'lib/schema_serializer.rb', line 18 def load_definition(path) self.definition = YamlExt.load(path) end |
Instance Method Details
#as_json(_options = nil) ⇒ Object
31 32 33 |
# File 'lib/schema_serializer.rb', line 31 def as_json( = nil) schema.serialize(self) end |
#schema ⇒ Object
35 36 37 |
# File 'lib/schema_serializer.rb', line 35 def schema ::SchemaSerializer.definition.schema(schema_name) end |
#schema_name ⇒ Object
39 40 41 42 43 |
# File 'lib/schema_serializer.rb', line 39 def schema_name return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer object.class.name end |