Sha256: 10b8ff7b5078a57ddc69b0fd76edfcc5ffb589f1bbe9363e92dfcf90c3488e08

Contents?: true

Size: 417 Bytes

Versions: 41

Compression:

Stored size: 417 Bytes

Contents

# frozen_string_literal: true

class MiniDefender::Rules::Numeric < MiniDefender::Rule
  def self.signature
    'numeric'
  end

  def coerce(value)
    value.is_a?(Numeric) ? value : Float(value.to_s)
  end

  def passes?(attribute, value, validator)
    value.is_a?(Numeric) || Float(value.to_s) rescue false
  end

  def message(attribute, value, validator)
    "The field must contain a numeric value."
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
mini_defender-0.3.13 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.12 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.11 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.10 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.9 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.8 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.7 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.6 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.5 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.2 lib/mini_defender/rules/numeric.rb
mini_defender-0.3.0 lib/mini_defender/rules/numeric.rb
mini_defender-0.2.0 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.10 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.9 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.8 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.6 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.4 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.3 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.2 lib/mini_defender/rules/numeric.rb
mini_defender-0.1.1 lib/mini_defender/rules/numeric.rb