Class: BazaModels::Validators::BaseValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/baza_models/validators/base_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name, args) ⇒ BaseValidator

Returns a new instance of BaseValidator.



4
5
6
7
# File 'lib/baza_models/validators/base_validator.rb', line 4

def initialize(attribute_name, args)
  @attribute_name = attribute_name
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



2
3
4
# File 'lib/baza_models/validators/base_validator.rb', line 2

def args
  @args
end

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



2
3
4
# File 'lib/baza_models/validators/base_validator.rb', line 2

def attribute_name
  @attribute_name
end

Instance Method Details

#fire?(model) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/baza_models/validators/base_validator.rb', line 9

def fire?(model)
  result = true

  if @args[:if]
    if @args.fetch(:if).is_a?(Symbol)
      result = model.__send__(@args.fetch(:if))
    else
      raise "Unknown 'if'-argument: #{@args[:if]} (#{@args[:if].class.name})"
    end
  end

  result
end