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.0".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.
26 27 28 |
# File 'lib/schema_serializer.rb', line 26 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)
46 47 48 49 50 |
# File 'lib/schema_serializer.rb', line 46 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.
15 16 17 |
# File 'lib/schema_serializer.rb', line 15 def definition @definition end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
12 13 14 |
# File 'lib/schema_serializer.rb', line 12 def object @object end |
Class Method Details
.load_definition(path) ⇒ Object
17 18 19 |
# File 'lib/schema_serializer.rb', line 17 def load_definition(path) self.definition = YamlExt.load(path) end |
Instance Method Details
#as_json(_options = nil) ⇒ Object
30 31 32 |
# File 'lib/schema_serializer.rb', line 30 def as_json( = nil) schema.serialize(self) end |
#schema ⇒ Object
34 35 36 |
# File 'lib/schema_serializer.rb', line 34 def schema ::SchemaSerializer.definition.schema(schema_name) end |
#schema_name ⇒ Object
38 39 40 41 42 |
# File 'lib/schema_serializer.rb', line 38 def schema_name return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer object.class.name end |