Sha256: 8da419a4e523e812f24c6fdafdb24b9e0719d14b815cc24b58628de8349fa494

Contents?: true

Size: 550 Bytes

Versions: 41

Compression:

Stored size: 550 Bytes

Contents

# frozen_string_literal: true

class MiniDefender::Rules::Between < MiniDefender::Rule
  def initialize(min, max)
    @min = min
    @max = max
  end

  def self.signature
    'between'
  end

  def self.make(args)
    self.new(args[0].to_i, args[1].to_i)
  end

  def passes?(attribute, value, validator)
    case value
    when String, Array, Hash
      @min <= value.length && value.length <= @max
    else
      false
    end
  end

  def message(attribute, value, validator)
    "The value length must be between #{@min} and #{@max}."
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
mini_defender-0.6.8 lib/mini_defender/rules/between.rb
mini_defender-0.6.7 lib/mini_defender/rules/between.rb
mini_defender-0.6.5 lib/mini_defender/rules/between.rb
mini_defender-0.6.4 lib/mini_defender/rules/between.rb
mini_defender-0.6.3 lib/mini_defender/rules/between.rb
mini_defender-0.6.2 lib/mini_defender/rules/between.rb
mini_defender-0.6.1 lib/mini_defender/rules/between.rb
mini_defender-0.6.0 lib/mini_defender/rules/between.rb
mini_defender-0.5.8 lib/mini_defender/rules/between.rb
mini_defender-0.5.7 lib/mini_defender/rules/between.rb
mini_defender-0.5.6 lib/mini_defender/rules/between.rb
mini_defender-0.5.5 lib/mini_defender/rules/between.rb
mini_defender-0.5.4 lib/mini_defender/rules/between.rb
mini_defender-0.5.3 lib/mini_defender/rules/between.rb
mini_defender-0.5.2 lib/mini_defender/rules/between.rb
mini_defender-0.5.1 lib/mini_defender/rules/between.rb
mini_defender-0.5.0 lib/mini_defender/rules/between.rb
mini_defender-0.4.1 lib/mini_defender/rules/between.rb
mini_defender-0.4.0 lib/mini_defender/rules/between.rb
mini_defender-0.3.14 lib/mini_defender/rules/between.rb