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.3.13 lib/mini_defender/rules/between.rb
mini_defender-0.3.12 lib/mini_defender/rules/between.rb
mini_defender-0.3.11 lib/mini_defender/rules/between.rb
mini_defender-0.3.10 lib/mini_defender/rules/between.rb
mini_defender-0.3.9 lib/mini_defender/rules/between.rb
mini_defender-0.3.8 lib/mini_defender/rules/between.rb
mini_defender-0.3.7 lib/mini_defender/rules/between.rb
mini_defender-0.3.6 lib/mini_defender/rules/between.rb
mini_defender-0.3.5 lib/mini_defender/rules/between.rb
mini_defender-0.3.2 lib/mini_defender/rules/between.rb
mini_defender-0.3.0 lib/mini_defender/rules/between.rb
mini_defender-0.2.0 lib/mini_defender/rules/between.rb
mini_defender-0.1.10 lib/mini_defender/rules/between.rb
mini_defender-0.1.9 lib/mini_defender/rules/between.rb
mini_defender-0.1.8 lib/mini_defender/rules/between.rb
mini_defender-0.1.6 lib/mini_defender/rules/between.rb
mini_defender-0.1.4 lib/mini_defender/rules/between.rb
mini_defender-0.1.3 lib/mini_defender/rules/between.rb
mini_defender-0.1.2 lib/mini_defender/rules/between.rb
mini_defender-0.1.1 lib/mini_defender/rules/between.rb