Sha256: 8c414e5aea7972bb53ca7634305b50e1832aa00aec1e2c173e07538cd66c8481

Contents?: true

Size: 593 Bytes

Versions: 7

Compression:

Stored size: 593 Bytes

Contents

module GoldenFleece
  module Model
    module Normalization
      include Utility

      def normalize_fleece
        self.class.fleece_context.schemas.each do |attribute, schema|
          persisted_json = read_attribute attribute
          computed_json = deep_stringify_keys schema.reduce({}) { |memo, (schema_name, schema)|
            memo[schema_name] = schema.value.compute(self)
            memo
          }

          if !persisted_json.nil? && persisted_json != computed_json
            write_attribute attribute, computed_json
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
golden_fleece-1.0.1 lib/golden_fleece/model/normalization.rb
golden_fleece-1.0.0 lib/golden_fleece/model/normalization.rb
golden_fleece-0.1.5 lib/golden_fleece/model/normalization.rb
golden_fleece-0.1.4 lib/golden_fleece/model/normalization.rb
golden_fleece-0.1.3 lib/golden_fleece/model/normalization.rb
golden_fleece-0.1.2 lib/golden_fleece/model/normalization.rb
golden_fleece-0.1.1 lib/golden_fleece/model/normalization.rb