Class: Ape::Validator

Inherits:
Object
  • Object
show all
Includes:
Util, ValidatorDsl
Defined in:
lib/ape/validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

included

Methods included from ValidatorDsl

included

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (protected)



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ape/validator.rb', line 72

def method_missing(name, *args)
  if (name == :enabled?)
    new_method = self.class.send(:define_method, 'enabled?') do
      return true
    end
  elsif (name == :deterministic?)
    new_method = self.class.send(:define_method, 'deterministic?') do
      return false
    end
  elsif (name == :manifest)
    new_method = self.class.send(:define_method, 'manifest') do
      return []
    end
  else
    super
  end
  new_method.call(args) if new_method
end

Instance Attribute Details

#authentObject

Returns the value of attribute authent.



10
11
12
# File 'lib/ape/validator.rb', line 10

def authent
  @authent
end

#reporterObject

Returns the value of attribute reporter.



10
11
12
# File 'lib/ape/validator.rb', line 10

def reporter
  @reporter
end

Class Method Details

.custom_validators(reporter, authent) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ape/validator.rb', line 12

def self.custom_validators(reporter, authent)
  validators = []
  Dir[Ape.home + '/validators/*.rb'].each do |v|
    require v
    class_name = v.gsub(/(.+\/validators\/)(.+)(.rb)/, '\2').gsub(/(^|_)(.)/) { $2.upcase }
    validator = eval("#{class_name}.new", binding, __FILE__, __LINE__)
    if validator.enabled?
      validator.reporter = reporter
      validator.authent = authent
      validators << validator
    end
  end
  validators
end

.instance(key, reporter, authent = nil) ⇒ Object

Raises:



27
28
29
30
31
32
33
# File 'lib/ape/validator.rb', line 27

def self.instance(key, reporter, authent = nil)
  validator = resolve_plugin(key, 'validators', 'validator')
  raise ValidationError, "Unknown validator #{key}" unless validator
  validator.reporter = reporter
  validator.authent = authent
  validator
end

Instance Method Details

#validate(opts = {}) ⇒ Object

Each validator implements its own bussiness logic. This method is executed by the main script

in order to assure that some aspect of atomPub implementation is correct

Raises:



39
40
41
# File 'lib/ape/validator.rb', line 39

def validate(opts = {})
  raise ValidationError, "superclass doesn't implement this method"
end