Class: CoverageInterpreter
- Inherits:
-
DslContext
- Object
- DslContext
- CoverageInterpreter
- Includes:
- Marshaller
- Defined in:
- lib/CoverageInterpreter.rb
Constant Summary collapse
- PRODUCTMODELS =
Hash.new
Class Method Summary collapse
Instance Method Summary collapse
- #columns(*args) ⇒ Object
- #coverage(*args) ⇒ Object
- #deriveActiveRecordDefinitionOfProduct(product) ⇒ Object
- #endcoverage(*args) ⇒ Object
- #endentity(*args) ⇒ Object
- #entity(*args) ⇒ Object
- #getResult ⇒ Object
- #hideFields(*args) ⇒ Object
-
#initialize(*args) ⇒ CoverageInterpreter
constructor
A new instance of CoverageInterpreter.
- #setProduct(product) ⇒ Object
- #use(*args) ⇒ Object
Methods inherited from DslContext
Constructor Details
#initialize(*args) ⇒ CoverageInterpreter
Returns a new instance of CoverageInterpreter.
32 33 34 35 36 |
# File 'lib/CoverageInterpreter.rb', line 32 def initialize(*args) @columns = 1 @hidden_fields = Set.new @modelsLoaded = false end |
Class Method Details
.execute(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/CoverageInterpreter.rb', line 12 def self.execute(*args) rules = polish_text(args[0]) #significant change to allow class instance variables to be set on the initialize, ahead #of the evaluation of the DSL - allows dynamic props to be sent to the class #see VPMSProductSchemaInterpreter, which gets a param from the package interpreter inst = (args.length > 1) ? self.new(args.slice(1,1)) : self.new inst.setProduct(args[2]) rules.each do |rule| result = inst.instance_eval(rule) #passes results as parm into code that was passed with call to execute (if any was) yield result if block_given? end inst.getResult end |
Instance Method Details
#columns(*args) ⇒ Object
49 50 51 |
# File 'lib/CoverageInterpreter.rb', line 49 def columns(*args) @columns = args[0].to_i end |
#coverage(*args) ⇒ Object
53 54 55 |
# File 'lib/CoverageInterpreter.rb', line 53 def coverage(*args) begin_erb(COVERAGE_DEF_ROOT, args) end |
#deriveActiveRecordDefinitionOfProduct(product) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/CoverageInterpreter.rb', line 185 def deriveActiveRecordDefinitionOfProduct(product) if (PRODUCTMODELS.has_key?(product)) productModel = PRODUCTMODELS[product.to_sym] else require 'ProductInterpreter' oilfile = File.join("#{DY_MODELS}/#{product}/DSL/product.oil") open(oilfile) {|f| @contents = f.read } dsl = @contents.to_s if (!dsl.include?("product :#{product}")) raise "#{DY_MODELS}/#{product}/DSL/product.oil does NOT contain a product defintion for #{product}" end productModel = ProductInterpreter.execute(dsl) PRODUCTMODELS[product.to_sym] = productModel end productModel end |
#endcoverage(*args) ⇒ Object
57 58 59 |
# File 'lib/CoverageInterpreter.rb', line 57 def endcoverage(*args) end_erb end |
#endentity(*args) ⇒ Object
65 66 67 |
# File 'lib/CoverageInterpreter.rb', line 65 def endentity(*args) end_erb end |
#entity(*args) ⇒ Object
61 62 63 |
# File 'lib/CoverageInterpreter.rb', line 61 def entity(*args) begin_erb(ENTITY_DEF_ROOT, args) end |
#getResult ⇒ Object
38 39 40 41 42 43 |
# File 'lib/CoverageInterpreter.rb', line 38 def getResult = "" @widgets.each { |k| << ",'#{k}'" } @erb = "<%= ci_widgets(#{[1..-1]}) %>\n" + @erb unless .length == 0 @erb end |
#hideFields(*args) ⇒ Object
45 46 47 |
# File 'lib/CoverageInterpreter.rb', line 45 def hideFields(*args) args[0].split('&').each { |a| @hidden_fields << a.to_sym } end |
#setProduct(product) ⇒ Object
69 70 71 |
# File 'lib/CoverageInterpreter.rb', line 69 def setProduct(product) @product = product end |
#use(*args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/CoverageInterpreter.rb', line 73 def use(*args) #puts "INTO USE WITH:#{args}" #the test on hidden_fields property is a bit too brutal in that it cuts out a whole part of the tree #it serves to provide the same hiding capability as we had in the iteration earlier this day #but more consideration especially around individual field level restriction needs to be considered #i.e. we may want to keep part of the tree but loose some of the fields at that level #so that we need considering in the code block below args.each { |a| return if @hidden_fields.include?(a.to_sym) unless a.class.name == 'Hash' } # If the last argument is a hash we assume it's a hash of overrides which we remove # and merge in later. args_hash = nil reached_leaf_nodes = false if args.last.class.name == 'Hash' args_hash = args.pop reached_leaf_nodes = true end #now figure out whether the last arg above leads to an empty hash #not strictly empty since every hash has an xpath property of the position in the class hierarchy #if so backup a level and read the property whose name = the last arg value passed in lastArg = "" specificProperty = false myHash = @prdhash["#{@argName}#{args}"] raise "Failed to find [#{@argName}#{args}] in [#{@argName}PropertyHash]" if myHash == nil # Have a look for meta data pertaining to the class which may specify a type. = @prdhash["#{@argName}#{args}MD"] = [:type] unless == nil if (myHash.length == 1) specificProperty = true reached_leaf_nodes = true lastArg = args.pop myHash = @prdhash["#{@argName}#{args}"] # Since we are delegating to our parent definition we look at that for a type # specification if we haven' already found one. #class_meta_data = @prdhash["#{@argName}#{args}MD"] if specific_widget == nil #specific_widget = class_meta_data[:type] unless class_meta_data == nil end @widgets << unless == nil @erb << "<% #{} \"#\{widgetROOT}/#{}\" do %>" unless == nil myHash.each do |property, value| if (property != 'xpath' and (property =~ /MD$/) == nil) then #properties of type HashWithIndifferentAccess hold metadata about the property if (value == "" && (!specificProperty || (specificProperty && property == "#{lastArg}"))) then if (@columns > 1) @erb << '<tr>' if @col == 1 @erb << "<td width=\"#{100/@columns}%\">" #@erb << "<div style=\"display: inline-block;float: left;width: #{(100/@columns)}%;\">" end = myHash["#{property}MD"] = .merge(args_hash) unless args_hash == nil sMetaData = "{" .each { |n, v| sMetaData << "'#{n}' => '#{v}'," } sMetaData << ":entityName => '#{@argName}#{args}'," sMetaData << ":propertyName => '#{property}'" sMetaData << "}" #puts "METADATA:#{property}:#{metaData['mask']}_input:#{metaData['type']}_input" @erb << "<% singleline_rowpanel \"#\{widgetROOT}/singleline_rowpanel\",\"#{sMetaData}\" do %>\n" @widgets << "singleline_rowpanel" if (['type'] != nil) then @widgets << "#{['type']}_input" @erb << "<% #{['type']}_input \"#\{widgetROOT}/#{['type']}_input\",\"#{sMetaData}\" do %>\n<% end %>" elsif (['mask'] != nil) then @widgets << "#{['mask']}_input" @erb << "<% #{['mask']}_input \"#\{widgetROOT}/#{['mask']}_input\",\"#{sMetaData}\" do %>\n<% end %>" else @widgets << "text_input" @erb << "<% text_input \"#\{widgetROOT}/text_input\",\"#{sMetaData}\" do %>\n<% end %>" end @erb << "\n<% end %>" if (@columns > 1) #@erb << '</div>' @erb << '</td>' @erb << '</tr>' if @col == @columns @col = 0 if @col == @columns @col += 1 end end end end @erb << '<% end %>' unless == nil if (!@modelsLoaded) req_stmt = deriveActiveRecordDefinitionOfProduct("#{@product}") eval(req_stmt) @modelsLoaded = true end if (args.length > 0 and !reached_leaf_nodes) children = walk_class_hierarchy("#{@argName}#{args}") if (children.length > 0) #puts "walking hierarchy for #{@argName}#{args}" children.each do |c| myHash = @prdhash["#{c}"] node_xpath = myHash[:xpath] arr = node_xpath.split('/') arr.shift #puts "use is:#{arr}" use("#{arr}") end end end end |