Sha256: 8bab78c27b5b6a715688a785f17a89b921be2abcee20d4614a361fe6cf5f6090

Contents?: true

Size: 772 Bytes

Versions: 15

Compression:

Stored size: 772 Bytes

Contents

module NxtSupport
  module PreprocessAttributes
    extend ActiveSupport::Concern

    class_methods do
      attr_reader :nxt_preprocessors

      def preprocess_attributes(*attributes, **options)
        attributes_to_process =
          if attributes.any?
            attributes.map(&:to_sym)
          else
            column_names.map(&:to_sym)
          end

        @nxt_preprocessors ||= []
        @nxt_preprocessors << NxtSupport::Preprocessor.new(attributes_to_process, options)
      end
    end

    included do
      before_validation do |record|
        nxt_preprocessors.each do |preprocessor|
          preprocessor.process(record)
        end
      end
    end

    private

    def nxt_preprocessors
      self.class.nxt_preprocessors
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nxt_support-0.6.0 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.5.0 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.4.3 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.4.2 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.4.1 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.4.0 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.3.0 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.2.1 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.2.0 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.16 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.15 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.9 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.8 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.7 lib/nxt_support/models/preprocess_attributes.rb
nxt_support-0.1.6 lib/nxt_support/models/preprocess_attributes.rb