Module: Inspector::Metadata
Defined Under Namespace
Classes: Map, Walker
Instance Attribute Summary collapse
Instance Method Summary
collapse
#be_email, #be_empty, #be_false, #be_true, #eq, #have, #have_at_least, #have_at_most, #method_missing, #validate
Methods included from Constraint
#negate!, #positive?, #validator
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Inspector::Constraints
Instance Attribute Details
Returns the value of attribute children_metadata.
8
9
10
|
# File 'lib/inspector/metadata.rb', line 8
def children_metadata
@children_metadata
end
|
#constraints ⇒ Object
Returns the value of attribute constraints.
8
9
10
|
# File 'lib/inspector/metadata.rb', line 8
def constraints
@constraints
end
|
#type ⇒ Object
Returns the value of attribute type.
8
9
10
|
# File 'lib/inspector/metadata.rb', line 8
def type
@type
end
|
Instance Method Details
#attribute(name, &block) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/inspector/metadata.rb', line 19
def attribute(name, &block)
@attribute_metadatas[name] ||= AttributeMetadata.new(@type, name)
if block_given?
block.arity == 1 ? yield(@attribute_metadatas[name]) : @attribute_metadatas[name].instance_eval(&block)
end
@attribute_metadatas[name]
end
|
60
61
62
|
# File 'lib/inspector/metadata.rb', line 60
def attribute_metadatas
@attribute_metadatas.values
end
|
#children(object, &block) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/inspector/metadata.rb', line 68
def children(object, &block)
object.each_with_index(&block)
rescue NoMethodError
raise "metadata for #{@type.inspect} contains children metadata, however " +
"#{object.inspect}.each_with_index is not defined"
end
|
#each_item(&block) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/inspector/metadata.rb', line 35
def each_item(&block)
@children_metadata ||= TypeMetadata.new(@type)
if block_given?
block.arity == 1 ? yield(@children_metadata) : @children_metadata.instance_eval(&block)
end
@children_metadata
end
|
#initialize(type) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/inspector/metadata.rb', line 12
def initialize(type)
@type = type
@constraints = []
@property_metadatas = {}
@attribute_metadatas = {}
end
|
#property(name, &block) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/inspector/metadata.rb', line 27
def property(name, &block)
@property_metadatas[name] ||= PropertyMetadata.new(@type, name)
if block_given?
block.arity == 1 ? yield(@property_metadatas[name]) : @property_metadatas[name].instance_eval(&block)
end
@property_metadatas[name]
end
|
64
65
66
|
# File 'lib/inspector/metadata.rb', line 64
def property_metadatas
@property_metadatas.values
end
|
#should(constraint = nil) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/inspector/metadata.rb', line 43
def should(constraint = nil)
return PositiveComparator.new(self) if constraint.nil?
@constraints << constraint
self
end
|
#should_not(constraint = nil) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/inspector/metadata.rb', line 51
def should_not(constraint = nil)
return NegativeComparator.new(self) if constraint.nil?
constraint.negate!
@constraints << constraint
self
end
|