Class: RestMyCase::AccusationAttorneys::Format

Inherits:
Each
  • Object
show all
Defined in:
lib/rest_my_case/accusation_attorneys/format.rb

Instance Attribute Summary

Attributes inherited from Each

#attributes

Attributes inherited from Base

#base, #options

Instance Method Summary collapse

Methods inherited from Each

#initialize, #validate

Methods inherited from Base

#initialize, #validate

Constructor Details

This class inherits a constructor from RestMyCase::AccusationAttorneys::Each

Instance Method Details

#check_validity!Object



15
16
17
18
19
20
21
22
# File 'lib/rest_my_case/accusation_attorneys/format.rb', line 15

def check_validity!
  unless options.include?(:with) ^ options.include?(:without)  # ^ == xor, or "exclusive or"
    raise ArgumentError, "Either :with or :without must be supplied (but not both)"
  end

  check_options_validity(options, :with)
  check_options_validity(options, :without)
end

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/rest_my_case/accusation_attorneys/format.rb', line 5

def validate_each(record, attribute, value)
  if options[:with]
    regexp = option_call(record, :with)
    record_error(record, attribute, :with, value) if value.to_s !~ regexp
  elsif options[:without]
    regexp = option_call(record, :without)
    record_error(record, attribute, :without, value) if value.to_s =~ regexp
  end
end