Module: Vinyl::Validators
- Defined in:
- lib/vinyl/validator.rb
Constant Summary collapse
- @@prefix =
use prefixs to avoid collisions betweeen variables and methods names
"validator_"- @@exclusion_list =
[]
Class Method Summary collapse
- .clean_exclusion_list ⇒ Object
- .exclude_global_validator(name) ⇒ Object
- .global_validators ⇒ Object
-
.method_missing(*args) ⇒ Object
Return false if no validator exists.
- .prefix ⇒ Object
- .run_validators(validators) ⇒ Object
Class Method Details
.clean_exclusion_list ⇒ Object
44 45 46 |
# File 'lib/vinyl/validator.rb', line 44 def self.clean_exclusion_list @@exclusion_list = Array.new end |
.exclude_global_validator(name) ⇒ Object
38 39 40 41 |
# File 'lib/vinyl/validator.rb', line 38 def self.exclude_global_validator(name) name = ["#{name}"] if name.instance_of? String @@exclusion_list |= name end |
.global_validators ⇒ Object
34 35 36 |
# File 'lib/vinyl/validator.rb', line 34 def self.global_validators @@global_validators ||= Array.new end |
.method_missing(*args) ⇒ Object
Return false if no validator exists
63 64 65 66 67 68 69 70 |
# File 'lib/vinyl/validator.rb', line 63 def self.method_missing(*args) #Return false if no validator exists if (Vinyl::controller.variables.include?(args[0])) then return Vinyl::get(args[0]) else STDOUT.puts "Warning: missing method #{args[0]}, Validator defaults to false" if Vinyl.config.warn_on_missing_validators return false end end |
.prefix ⇒ Object
30 31 32 |
# File 'lib/vinyl/validator.rb', line 30 def self.prefix @@prefix end |
.run_validators(validators) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vinyl/validator.rb', line 48 def self.run_validators(validators) validators = validators + (Vinyl.global_validators - @@exclusion_list) clean_exclusion_list if validators.nil? || validators.empty? then return !Vinyl.config.force_access_control end validators.each do |method_name| pass = Vinyl::Validators.send(prefix + method_name) if(pass == false) then return false end end return true end |