Sha256: 274c15a6165fae588b214da23bb229e43fda042631d8dc762f8d331505dd70d0

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

module Mobility
  module Sequel
=begin

Internal class used to force Sequel model to notice changes when mobility
setter method is called.

=end
    class ColumnChanges < Module
      # @param [Array<String>] attributes Backend attributes
      def initialize(*attributes)
        attributes.each do |attribute|
          define_method "#{attribute}=" do |value, **options|
            if !options[:super] && send(attribute) != value
              locale = options[:locale] || Mobility.locale
              column = attribute.to_sym
              column_with_locale = :"#{attribute}_#{Mobility.normalize_locale(locale)}"
              @changed_columns = changed_columns | [column, column_with_locale]
            end
            super(value, **options)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.5.1 lib/mobility/sequel/column_changes.rb
mobility-0.5.0 lib/mobility/sequel/column_changes.rb