iab-Oil 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'set'
2
2
  require File.join(File.dirname(__FILE__),'DSLContext')
3
+ require 'Marshaller'
3
4
 
4
5
  #create class that fills in for the RAILS class when rails is not around, e.g. when testing
5
6
  #when RAILS is around this will have no effect
@@ -7,12 +8,14 @@ class HashWithIndifferentAccess < Hash
7
8
  end
8
9
 
9
10
  class CoverageInterpreter < DslContext
10
-
11
- bubble :than, :is, :list, :the, :to, :at, :it, :end
11
+ include Marshaller
12
12
 
13
+ bubble :than, :is, :list, :the, :to, :at, :it, :end
14
+ PRODUCTMODELS = Hash.new
13
15
  def initialize(*args)
14
16
  @columns = 1
15
17
  @hidden_fields = Set.new
18
+ @modelsLoaded = false
16
19
  end
17
20
 
18
21
  def getResult
@@ -47,6 +50,7 @@ class CoverageInterpreter < DslContext
47
50
  end
48
51
 
49
52
  def use(*args)
53
+ #puts "INTO USE WITH:#{args}"
50
54
  #the test on hidden_fields property is a bit too brutal in that it cuts out a whole part of the tree
51
55
  #it serves to provide the same hiding capability as we had in the iteration earlier this day
52
56
  #but more consideration especially around individual field level restriction needs to be considered
@@ -57,7 +61,11 @@ class CoverageInterpreter < DslContext
57
61
  # If the last argument is a hash we assume it's a hash of overrides which we remove
58
62
  # and merge in later.
59
63
  args_hash = nil
60
- args_hash = args.pop if args.last.class.name == 'Hash'
64
+ reached_leaf_nodes = false
65
+ if args.last.class.name == 'Hash'
66
+ args_hash = args.pop
67
+ reached_leaf_nodes = true
68
+ end
61
69
 
62
70
  #now figure out whether the last arg above leads to an empty hash
63
71
  #not strictly empty since every hash has an xpath property of the position in the class hierarchy
@@ -73,6 +81,7 @@ class CoverageInterpreter < DslContext
73
81
 
74
82
  if (myHash.length == 1)
75
83
  specificProperty = true
84
+ reached_leaf_nodes = true
76
85
  lastArg = args.pop
77
86
  myHash = @prdhash["#{@argName}#{args}"]
78
87
  # Since we are delegating to our parent definition we look at that for a type
@@ -129,9 +138,46 @@ class CoverageInterpreter < DslContext
129
138
  end
130
139
  end
131
140
  end
132
- @erb << '<% end %>' unless specific_widget == nil
141
+ @erb << '<% end %>' unless specific_widget == nil
142
+
143
+ if (!@modelsLoaded)
144
+ req_stmt = deriveActiveRecordDefinitionOfProduct('Telenexus')
145
+ eval(req_stmt)
146
+ @modelsLoaded = true
147
+ end
148
+ if (args.length > 0 and !reached_leaf_nodes)
149
+ children = walk_class_hierarchy("#{@argName}#{args}")
150
+ if (children.length > 0)
151
+ #puts "walking hierarchy for #{@argName}#{args}"
152
+ children.each do |c|
153
+ myHash = @prdhash["#{c}"]
154
+ node_xpath = myHash[:xpath]
155
+ arr = node_xpath.split('/')
156
+ arr.shift
157
+ #puts "use is:#{arr}"
158
+ use("#{arr}")
159
+ end
160
+ end
161
+ end
133
162
  end
134
-
163
+
164
+ def deriveActiveRecordDefinitionOfProduct(product)
165
+ if (PRODUCTMODELS.has_key?(product))
166
+ productModel = PRODUCTMODELS[product.to_sym]
167
+ else
168
+ require 'ProductInterpreter'
169
+ oilfile = File.join("#{DY_MODELS}/#{product}/DSL/product.oil")
170
+ open(oilfile) {|f| @contents = f.read }
171
+ dsl = @contents.to_s
172
+ if (!dsl.include?("product :#{product}"))
173
+ raise "#{DY_MODELS}/#{product}/DSL/product.oil does NOT contain a product defintion for #{product}"
174
+ end
175
+ productModel = ProductInterpreter.execute(dsl)
176
+ PRODUCTMODELS[product.to_sym] = productModel
177
+ end
178
+ productModel
179
+ end
180
+
135
181
  private
136
182
  def begin_erb(dsl_root, *args)
137
183
  @widgets = Set.new
@@ -21,9 +21,19 @@ class DataModelInterpreter < DslContext
21
21
  def enddatamodel(*args)
22
22
  end
23
23
 
24
- def createNewElement(name,coverage,parent,type)
24
+ def createNewElement(name,ctype,coverage,parent,type) #the type tells us if it is an entity, or coverage, or nil if a simple element
25
25
  e = ElementFactory(name,coverage,parent,type)
26
26
  @elementTree.last.children.push e if @elementTree.last and @elementTree.length > 0
27
+ if ctype and ctype != name
28
+ #copy fields from complex type definition to be used in this clone
29
+ @elements.each do |node|
30
+ if node.name == ctype
31
+ e.fields = node.fields
32
+ e.children = node.children
33
+ e.parent = @elementTree.last
34
+ end
35
+ end
36
+ end
27
37
  @elementTree.push e
28
38
  end
29
39
 
@@ -40,7 +50,7 @@ class DataModelInterpreter < DslContext
40
50
  end
41
51
 
42
52
  def element(*args)
43
- createNewElement(args[0],false,@elementTree.last,nil)
53
+ createNewElement(args[0],nil,false,@elementTree.last,nil)
44
54
  end
45
55
 
46
56
  def endelement(*args)
@@ -48,7 +58,7 @@ class DataModelInterpreter < DslContext
48
58
  end
49
59
 
50
60
  def coverage(*args)
51
- createNewElement(args[0]+ "Coverage",true,@elementTree.last,"coverages")
61
+ createNewElement(args[0]+ "Coverage",nil,true,@elementTree.last,"coverages")
52
62
  end
53
63
 
54
64
  def endcoverage(*args)
@@ -56,7 +66,7 @@ class DataModelInterpreter < DslContext
56
66
  end
57
67
 
58
68
  def entity(*args)
59
- createNewElement(args[0],true,@elementTree.last,"entities")
69
+ createNewElement(args[0],nil,true,@elementTree.last,"entities")
60
70
  end
61
71
 
62
72
  def endentity(*args)
@@ -70,7 +80,9 @@ class DataModelInterpreter < DslContext
70
80
  else
71
81
  parent = @elementTree.last
72
82
  end
73
- createNewElement(args[0][:ctype],false,parent,nil) #the parent is nil here since a complex type may be used by many coverages or entities
83
+ createNewElement(args[0][:name],args[0][:ctype],false,parent,nil)
84
+ #pop the tree since createNewElement pushes new element to the tree
85
+ #since has to work for enties and coverages
74
86
  @elementTree.pop
75
87
  else
76
88
  @elementTree.last.fields.push args[0]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iab-Oil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Mawdsley