Class: SlideField::ObjectRules::Base
- Inherits:
-
Object
- Object
- SlideField::ObjectRules::Base
show all
- Defined in:
- lib/slidefield/object_rules.rb,
lib/slidefield/objects/_base.rb
Constant Summary
collapse
- @@cache =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
13
14
15
16
|
# File 'lib/slidefield/object_rules.rb', line 13
def initialize
@properties = []
@children = []
end
|
Class Method Details
.get ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/slidefield/object_rules.rb', line 60
def self.get
if instance = @@cache[self]
instance
else
instance = self.new
instance.rules
@@cache[self] = instance
end
end
|
Instance Method Details
#accepted_children ⇒ Object
51
52
53
|
# File 'lib/slidefield/object_rules.rb', line 51
def accepted_children
@children.collect {|hash| hash[:type] }
end
|
#default_value(name) ⇒ Object
46
47
48
49
|
# File 'lib/slidefield/object_rules.rb', line 46
def default_value(name)
rule = @properties.select {|hash| hash[:name] == name }.first
rule[:default] if rule
end
|
#matching_properties(type) ⇒ Object
41
42
43
44
|
# File 'lib/slidefield/object_rules.rb', line 41
def matching_properties(type)
matches = @properties.select {|hash| hash[:type] == type }
matches.collect {|hash| hash[:name] }
end
|
#optional_properties ⇒ Object
31
32
33
34
|
# File 'lib/slidefield/object_rules.rb', line 31
def optional_properties
required = @properties.select {|hash| !hash[:default].nil? }
required.collect {|hash| hash[:name] }
end
|
#properties_names ⇒ Object
18
19
20
|
# File 'lib/slidefield/object_rules.rb', line 18
def properties_names
@properties.collect {|hash| hash[:name] }
end
|
#properties_types ⇒ Object
22
23
24
|
# File 'lib/slidefield/object_rules.rb', line 22
def properties_types
@properties.collect {|hash| hash[:type] }.uniq
end
|
#required_properties ⇒ Object
26
27
28
29
|
# File 'lib/slidefield/object_rules.rb', line 26
def required_properties
required = @properties.select {|hash| hash[:default].nil? }
required.collect {|hash| hash[:name] }
end
|
#requirements_of_child(type) ⇒ Object
55
56
57
58
|
# File 'lib/slidefield/object_rules.rb', line 55
def requirements_of_child(type)
rule = @children.select {|hash| hash[:type] == type }.first
rule[:requirements] if rule
end
|
#rules ⇒ Object
3
4
5
6
|
# File 'lib/slidefield/objects/_base.rb', line 3
def rules
child :include
child :debug
end
|
#type_of_property(name) ⇒ Object
36
37
38
39
|
# File 'lib/slidefield/object_rules.rb', line 36
def type_of_property(name)
rule = @properties.select {|hash| hash[:name] == name }.first
rule[:type] if rule
end
|