Sha256: 7100aa981855d30d92434e9920b4189fc991e572ba98bdf6f4d0c00b9e280f4e

Contents?: true

Size: 673 Bytes

Versions: 12

Compression:

Stored size: 673 Bytes

Contents

module ActsAsScrubbable
  module Scrub

    def scrub!
      if self.class.scrubbable?
        _updates = {}

        scrubbable_fields.each do |_field, value|
          unless self.respond_to?(_field)
            raise ArgumentError, "#{self.class} do not respond to #{_field}"
          end
          next if self.send(_field).blank?

          if ActsAsScrubbable.scrub_map.keys.include?(value)
            _updates[_field] = ActsAsScrubbable.scrub_map[value].call
          else
            puts "Undefined scrub: #{value} for #{self.class}#{_field}"
           end
        end

        self.update_columns(_updates) unless _updates.empty?
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
acts_as_scrubbable-0.1.4 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.1.3 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.1.2 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.1.1 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.1.0 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.9 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.8 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.7 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.6 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.5 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.4 lib/acts_as_scrubbable/scrub.rb
acts_as_scrubbable-0.0.3 lib/acts_as_scrubbable/scrub.rb