Module: Valcro

Defined in:
lib/valcro.rb,
lib/valcro/error.rb,
lib/valcro/runner.rb,
lib/valcro/version.rb,
lib/valcro/error_list.rb

Defined Under Namespace

Modules: ClassMethods Classes: Error, ErrorList, Runner

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/valcro.rb', line 6

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#error_messagesObject



18
19
20
# File 'lib/valcro.rb', line 18

def error_messages
  errors.to_s
end

#errorsObject



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

def errors
  @error_list ||= Valcro::ErrorList.new
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/valcro.rb', line 14

def valid?
  !errors.any?
end

#validateObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/valcro.rb', line 22

def validate
  errors.clear!
  self.class.validators.each do |validator_class|
    validation_runner.add_validator validator_class.new(self)
  end
  self.class.validation_blocks.each do |validation_block|
    instance_eval(&validation_block)
  end
  validation_runner.validate
end

#validation_runnerObject



33
34
35
# File 'lib/valcro.rb', line 33

def validation_runner
  @validation_runner ||= Valcro::Runner.new(errors)
end