Class: ObjectModel::Metadata::Validation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method = nil, &block) ⇒ Validation

Returns a new instance of Validation.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ObjectModel/Metadata/validate.rb', line 22

def initialize method = nil, &block
	if method
		method.should! :be_a, Symbol
		block.should! :be_nil
		@method = method					
	elsif block
		method.should! :be_nil
		@block = block
	else
		should! :be_never_called
	end
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



20
21
22
# File 'lib/ObjectModel/Metadata/validate.rb', line 20

def block
  @block
end

#methodObject (readonly)

Returns the value of attribute method.



20
21
22
# File 'lib/ObjectModel/Metadata/validate.rb', line 20

def method
  @method
end

Instance Method Details

#validate(entity) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/ObjectModel/Metadata/validate.rb', line 35

def validate entity
	if @method
		entity.send @method
	elsif @block
		entity.instance_eval &@block
	else
		should! :be_never_called
	end
end