Module: Intrinsic::Intrinsicism::Validation

Defined in:
lib/intrinsic/intrinsicism/validation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/intrinsic/intrinsicism/validation.rb', line 4

def errors
  @errors
end

#validatorsObject (readonly)

Returns the value of attribute validators.



4
5
6
# File 'lib/intrinsic/intrinsicism/validation.rb', line 4

def validators
  @validators
end

Class Method Details

.included(subject) ⇒ Object



6
7
8
9
# File 'lib/intrinsic/intrinsicism/validation.rb', line 6

def self.included(subject)
  super
  subject.extend Validation
end

Instance Method Details

#add_validators(property = nil, block = nil) ⇒ Object



20
21
22
23
# File 'lib/intrinsic/intrinsicism/validation.rb', line 20

def add_validators(property = nil, block = nil)
  @validators ||= {}
  @validators[property] = block
end

#is_valid?(property = nil) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/intrinsic/intrinsicism/validation.rb', line 16

def is_valid?(property = nil)
  self.class.validators.all? { |property, validator| validate property, validator }
end

#validation_for(property, &block) ⇒ Object



11
12
13
14
# File 'lib/intrinsic/intrinsicism/validation.rb', line 11

def validation_for(property, &block)
  check_for_property property
  add_validators property, block
end