Sha256: 697ed5d72f96c11f84f5456edf24e3ef3621484ce6a44e311e2b97789afa07f7

Contents?: true

Size: 757 Bytes

Versions: 41

Compression:

Stored size: 757 Bytes

Contents

# frozen_string_literal: true

class MiniDefender::Rules::NotEndingWith < MiniDefender::Rule
  def initialize(fragments)
    unless fragments.is_a?(Array) && !fragments.empty? && fragments.all? { |f| f.is_a?(String) }
      raise ArgumentError, 'Expected an array of strings.'
    end

    @fragments = fragments
  end

  def self.signature
    'not_ending_with'
  end

  def self.make(args)
    new(args)
  end

  def passes?(attribute, value, validator)
    @fragments.any? { |f| !value.to_s.end_with?(f) }
  end

  def message(attribute, value, validator)
    if @fragments.length == 1
      "The value should not end with #{@fragments[0]}."
    else
      "The value should not end with one of the following #{@fragments.join(', ')}."
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

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