Module: Squishify

Included in:
ApplicationRecord
Defined in:
app/models/concerns/squishify.rb

Overview

Extends ApplicationRecord and provides squishify configuration to remove duplicated whitespace from strings

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

rubocop:todo Metrics/MethodLength



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/concerns/squishify.rb', line 5

def self.extended(base) # rubocop:todo Metrics/MethodLength
  base.instance_eval do
    def squishify(*names)
      class_eval do
        before_validation do |record|
          names.each do |name|
            value = record.send(name)
            record.send(name.to_s + '=', value.squish) if value.is_a? String
          end
        end
      end
    end
  end
end