Sha256: 094147bbb13281015ae75ca1090cdd16f8f65922e6c864cda0b44cde5a354605

Contents?: true

Size: 739 Bytes

Versions: 2

Compression:

Stored size: 739 Bytes

Contents

# frozen_string_literal: true

module JsonbAccessor
  module Helpers
    module_function

    def active_record_default_timezone
      ActiveRecord.try(:default_timezone) || ActiveRecord::Base.default_timezone
    end

    # Replaces all keys in `attributes` that have a defined store_key with the store_key
    def convert_keys_to_store_keys(attributes, store_key_mapping)
      attributes.stringify_keys.transform_keys do |key|
        store_key_mapping[key] || key
      end
    end

    # Replaces all keys in `attributes` that have a defined store_key with the named key (alias)
    def convert_store_keys_to_keys(attributes, store_key_mapping)
      convert_keys_to_store_keys(attributes, store_key_mapping.invert)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jsonb_accessor-1.3.5 lib/jsonb_accessor/helpers.rb
jsonb_accessor-1.3.4 lib/jsonb_accessor/helpers.rb