Class: Fabulator::Structural
- Inherits:
-
Action
- Object
- Action
- Fabulator::Structural
show all
- Defined in:
- lib/fabulator/structural.rb
Direct Known Subclasses
Core::Actions::Choose, Core::Actions::ForEach, Core::Structurals::Group, Core::Structurals::State, Core::Structurals::StateMachine, Core::Structurals::Transition, Lib::Action, Lib::Attribute, Lib::Consolidation, Lib::Function, Lib::Mapping, Lib::Reduction, Lib::Structural, Lib::Template
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Structural.
4
5
6
7
8
|
# File 'lib/fabulator/structural.rb', line 4
def initialize
@context = Fabulator::Expr::Context.new
self.init_attribute_storage
end
|
Class Method Details
.accepts_structural?(ns, nom) ⇒ Boolean
75
76
77
78
79
|
# File 'lib/fabulator/structural.rb', line 75
def self.accepts_structural?(ns, nom)
s = self.structurals
in_s = (s[ns][nom.to_sym] rescue nil)
return !in_s.nil?
end
|
.contained_in(ns, nom, h = {}) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/fabulator/structural.rb', line 45
def self.contained_in(ns, nom, h = {})
@@contained_in ||= { }
@@contained_in[ns] ||= { }
@@contained_in[ns][nom.to_sym] ||= { }
@@contained_in[ns][nom.to_sym][self.namespace] ||= { }
@@contained_in[ns][nom.to_sym][self.namespace][self.element.to_sym] = { :as => :contained }.update(h)
end
|
.contains(nom, opts = { }) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/fabulator/structural.rb', line 34
def self.contains(nom, opts = { })
ns = opts[:ns] || self.namespace
@@structurals ||= { }
@@structurals[self.name] ||= { }
@@structurals[self.name][ns] ||= { }
@@structurals[self.name][ns][nom.to_sym] = opts
self.module_eval {
attr_accessor (opts[:as] || nom.to_s.pluralize).to_sym
}
end
|
.element(nom = nil) ⇒ Object
28
29
30
31
32
|
# File 'lib/fabulator/structural.rb', line 28
def self.element(nom = nil)
@@elements ||= { }
@@elements[self.name] = nom unless nom.nil?
@@elements[self.name]
end
|
.structurals ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/fabulator/structural.rb', line 54
def self.structurals
ret = @@structurals[self.name]
els = self.element
els = [ els ] unless els.is_a?(Array)
return ret if self.element.nil?
@@contained_in ||= { }
return ret if @@contained_in[self.namespace].nil?
pot = @@contained_in[self.namespace][self.element.to_sym]
return ret if pot.nil? || pot.empty?
pot.each_pair do |ns, noms|
ret[ns] ||= { }
ret[ns] = ret[ns].update(noms)
end
ret
end
|
Instance Method Details
#accepts_structural?(ns, nom) ⇒ Boolean
81
82
83
|
# File 'lib/fabulator/structural.rb', line 81
def accepts_structural?(ns, nom)
self.class.accepts_structural?(ns, nom)
end
|
#compile_xml(xml, context = nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fabulator/structural.rb', line 10
def compile_xml(xml, context = nil)
XML.default_line_numbers = true
if xml.is_a?(String)
xml = LibXML::XML::Document.string xml
end
if xml.is_a?(LibXML::XML::Document)
xml = xml.root
end
if context.nil?
@context = @context.merge(xml)
else
@context = context.merge(xml)
end
self.setup(xml)
end
|