Sha256: 4e72ae76798cbddef1238aa5d73c90504ea947b6849dbb8d2f206515b2b8d098

Contents?: true

Size: 826 Bytes

Versions: 5

Compression:

Stored size: 826 Bytes

Contents

require "json"
require 'couchbase/json_transcoder'
require 'couchbase-orm/json_schema'

module CouchbaseOrm
  class JsonTranscoder < Couchbase::JsonTranscoder

    attr_reader :ignored_properties, :json_validation_config

    def initialize(ignored_properties: [], json_validation_config: {}, **options, &block)
      @ignored_properties = ignored_properties
      @json_validation_config = json_validation_config
      super(**options, &block)
    end

    def decode(blob, _flags)
      original = super
      original&.except(*ignored_properties)
    end

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
couchbase-orm-2.0.4 lib/couchbase-orm/json_transcoder.rb
couchbase-orm-2.0.3 lib/couchbase-orm/json_transcoder.rb
couchbase-orm-2.0.2 lib/couchbase-orm/json_transcoder.rb
couchbase-orm-2.0.1 lib/couchbase-orm/json_transcoder.rb
couchbase-orm-2.0.0 lib/couchbase-orm/json_transcoder.rb