Class: CouchbaseOrm::JsonTranscoder
- Inherits:
-
Couchbase::JsonTranscoder
- Object
- Couchbase::JsonTranscoder
- CouchbaseOrm::JsonTranscoder
- Defined in:
- lib/couchbase-orm/json_transcoder.rb
Instance Attribute Summary collapse
-
#ignored_properties ⇒ Object
readonly
Returns the value of attribute ignored_properties.
-
#json_validation_config ⇒ Object
readonly
Returns the value of attribute json_validation_config.
Instance Method Summary collapse
- #decode(blob, _flags) ⇒ Object
- #encode(document) ⇒ Object
-
#initialize(ignored_properties: [], json_validation_config: {}, **options, &block) ⇒ JsonTranscoder
constructor
A new instance of JsonTranscoder.
Constructor Details
#initialize(ignored_properties: [], json_validation_config: {}, **options, &block) ⇒ JsonTranscoder
Returns a new instance of JsonTranscoder.
10 11 12 13 14 |
# File 'lib/couchbase-orm/json_transcoder.rb', line 10 def initialize(ignored_properties: [], json_validation_config: {}, **, &block) @ignored_properties = ignored_properties @json_validation_config = json_validation_config super(**, &block) end |
Instance Attribute Details
#ignored_properties ⇒ Object (readonly)
Returns the value of attribute ignored_properties.
8 9 10 |
# File 'lib/couchbase-orm/json_transcoder.rb', line 8 def ignored_properties @ignored_properties end |
#json_validation_config ⇒ Object (readonly)
Returns the value of attribute json_validation_config.
8 9 10 |
# File 'lib/couchbase-orm/json_transcoder.rb', line 8 def json_validation_config @json_validation_config end |
Instance Method Details
#decode(blob, _flags) ⇒ Object
16 17 18 19 |
# File 'lib/couchbase-orm/json_transcoder.rb', line 16 def decode(blob, _flags) original = super original&.except(*ignored_properties) end |
#encode(document) ⇒ Object
21 22 23 24 25 |
# File 'lib/couchbase-orm/json_transcoder.rb', line 21 def encode(document) original = super CouchbaseOrm::JsonSchema::Validator.new(json_validation_config).validate_entity(document, original[0]) if document.present? && !original.empty? && json_validation_config[:enabled] original end |