module AutoFormatAttributes

Constants

VERSION

Public Instance Methods

auto_capitalize_attributes(*attributes) click to toggle source
# File lib/auto_format_attributes.rb, line 16
def auto_capitalize_attributes(*attributes)
  auto_modify_attributes(attributes, :capitalize)
end
auto_downcase_attributes(*attributes) click to toggle source
# File lib/auto_format_attributes.rb, line 12
def auto_downcase_attributes(*attributes)
  auto_modify_attributes(attributes, :downcase)
end
auto_titleize_attributes(*attributes) click to toggle source
# File lib/auto_format_attributes.rb, line 4
def auto_titleize_attributes(*attributes)
  auto_modify_attributes(attributes, :titleize)
end
auto_upcase_attributes(*attributes) click to toggle source
# File lib/auto_format_attributes.rb, line 8
def auto_upcase_attributes(*attributes)
  auto_modify_attributes(attributes, :upcase)
end

Private Instance Methods

auto_modify_attributes(attributes, method) click to toggle source
# File lib/auto_format_attributes.rb, line 22
def auto_modify_attributes(attributes, method)
  attributes.each do |attribute|
    before_validation do |record|
      if record[attribute].respond_to? method
        record[attribute] = record[attribute].method(method).call
      end
    end
  end
end