Sha256: 655418fc1b9b46ce2a43582b8cf6c9d49992dade08c7bf600c45e06c7c895940

Contents?: true

Size: 687 Bytes

Versions: 3

Compression:

Stored size: 687 Bytes

Contents

module ActiveModel
  module Validations
    def has_error_on(attribute, error)
      return false unless self.respond_to?(:valid?)
      self.valid?
      self.errors.messages[attribute].try(:include?, error)
    end
  end


  class Errors
    def generate_message(attribute, type = :invalid, options = {})
      message = type.to_sym
      message_table[message] || message
    end


    def message_table
      {
        present: :absence,
        accepted: :acceptance,
        invalid: :format,
        not_a_number: :numericality,
        not_an_integer: :numericality,
        blank: :presence,
        wrong_length: :length
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yorisoi-0.0.3 spec/supports/active_model.rb
yorisoi-0.0.2 spec/supports/active_model.rb
yorisoi-0.0.1 spec/supports/active_model.rb