Class: Kongo::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/validate/kongo.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Model

Returns a new instance of Model.



43
44
45
46
47
# File 'lib/validate/kongo.rb', line 43

def initialize(*args)
  ret = original_initialize(*args)
  @validator = (@@validations ||= {})[@coll.name.to_sym]
  ret
end

Class Method Details

.add_validation_extension(collection_name, mod) ⇒ Object

This is the same as add_extension, but should be used to add validation extensions, which are implemented differently from regular extensions.



36
37
38
# File 'lib/validate/kongo.rb', line 36

def self.add_validation_extension(collection_name, mod)
  (@@validations ||= {})[collection_name.to_sym] = mod.validations
end

Instance Method Details

#failuresObject



54
55
56
# File 'lib/validate/kongo.rb', line 54

def failures
  @validator.failures
end

#original_initializeObject

Override initialize to also set @validator.



42
# File 'lib/validate/kongo.rb', line 42

alias :original_initialize :initialize

#validates?Boolean

Implements interface to validations via the two usual methods.

Returns:

  • (Boolean)


51
52
53
# File 'lib/validate/kongo.rb', line 51

def validates?
  @validator.validates?(self)
end