Module: Kharon::Factory

Defined in:
lib/validator_factory.rb

Constant Summary collapse

@@use_exceptions =

Returns TRUE if Kharon currently use exceptions, FALSE if not.

Returns:

  • TRUE if Kharon currently use exceptions, FALSE if not.

true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#use_exceptionsObject



# File 'lib/validator_factory.rb', line 7

Class Method Details

.configure(&block) ⇒ Object

Allows you to pass a whole block to configure the Kharon module.

Parameters:

  • block (Hash)

    a block of configuration instructions to pass to the module. See documentation for further informations.



19
20
21
# File 'lib/validator_factory.rb', line 19

def self.configure(&block)
  self.instance_eval(&block)
end

.use_exceptions(status) ⇒ Object

Sets the use of exceptions in the whole process.

Parameters:

  • status (Boolean)

    TRUE if you want to use the eceptions, FALSE if not.



25
26
27
# File 'lib/validator_factory.rb', line 25

def self.use_exceptions(status)
  @@use_exceptions = status
end

.uses_exceptions?Boolean

Fancy method to know if the module uses the exceptions or not.

Returns:

  • (Boolean)


30
31
32
# File 'lib/validator_factory.rb', line 30

def self.uses_exceptions?
  return @@use_exceptions
end

.validator(datas) ⇒ Object

Acts as a creation method for validators, considering the options you transmitted.

Parameters:

  • datas (Hash)

    the datas to validate in the validator.



13
14
15
# File 'lib/validator_factory.rb', line 13

def self.validator(datas)
  @@use_exceptions ? Kharon::Validator.new(datas) : Kharon::CoolValidator.new(datas)
end