Class: Riddl::Wrapper::Declaration
- Inherits:
-
WrapperUtils
- Object
- WrapperUtils
- Riddl::Wrapper::Declaration
- Defined in:
- lib/ruby/riddl/wrapper/declaration.rb,
lib/ruby/riddl/wrapper/declaration/tile.rb,
lib/ruby/riddl/wrapper/declaration/facade.rb,
lib/ruby/riddl/wrapper/declaration/interface.rb
Defined Under Namespace
Classes: Facade, Interface, Tile
Instance Method Summary collapse
- #description ⇒ Object
- #description_xml ⇒ Object
- #get_resource(path) ⇒ Object
-
#initialize(riddl) ⇒ Declaration
constructor
A new instance of Declaration.
- #paths ⇒ Object
-
#visualize_facade(res = @facade.resource, what = '') ⇒ Object
}}}.
-
#visualize_tiles_and_compositions ⇒ Object
}}}.
- #visualize_tiles_and_layers ⇒ Object
Constructor Details
#initialize(riddl) ⇒ Declaration
Returns a new instance of Declaration.
60 61 62 63 64 65 66 67 68 69 70 71 72 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 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 60 def initialize(riddl) @facade = Riddl::Wrapper::Declaration::Facade.new @namespaces = riddl.namespaces #{{{ ### create single tiles @tiles = [] @interfaces = {} riddl.find("/dec:declaration/dec:interface").each do |int| @interfaces[int.attributes['name']] = [int.attributes['location'],int.find("des:description").first] end riddl.find("/dec:declaration/dec:facade/dec:tile").each do |tile| @tiles << (til = Tile.new) til.base_path(tile.attributes['path'] || '/') # ^ above.clean! # for overlapping tiles, each tile gets an empty path TODO later = [] tile.find("dec:layer").each_with_index do |layer,index| apply_to = layer.find("dec:apply-to") block = layer.find("dec:block") lname = layer.attributes['name'] lpath, des = @interfaces[lname] desres = des.find("des:resource").first if apply_to.empty? int = Interface.new(lname,"/",lpath,"/",des) rec = desres.attributes['recursive'] til.add_description(des,desres,"/",index,int,block,rec) else apply_to.each do |at| t = at.to_s.sub(/^\/*/,'').split(/(?<!\*\*)\//) if t.last == "**/*" || t.last == "*" later << [des,desres,lname,lpath,at.to_s.strip,index,block,t.last == "**/*" ? :descendants : :children] else int = Interface.new(lname,at.to_s,lpath,"/",des) til.add_description(des,desres,at.to_s,index,int,block) end end end end paths = @tiles.map do |ttil| # extract all currently existing paths for all tiles rpaths(ttil.resource).map{|a,b| a} end.flatten.uniq later.each do |lat| mpath = lat[4].gsub(/\/\*\*\/\*$/,'').gsub(/\/\*$/,'') paths.each do |path| pbefore, pafter = path[0..mpath.length].chop, path[mpath.length+1..-1] if mpath == pbefore if (lat[7] == :descendants && pafter != '') || (lat[7] == :children && !pafter.nil? && pafter != '' && pafter !~ /\//) int = Interface.new(lat[2],path,lat[3],"/",lat[1]) til.add_description(lat[0],lat[1],path,lat[5],int,lat[6]) end end end end til.compose! end ### merge tiles into a facade @tiles.each do |til| @facade.merge_tiles(til.resource) end #}}} end |
Instance Method Details
#description ⇒ Object
21 22 23 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 21 def description Riddl::Wrapper.new(@facade.description_xml(@namespaces)) end |
#description_xml ⇒ Object
17 18 19 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 17 def description_xml @facade.description_xml(@namespaces) end |
#get_resource(path) ⇒ Object
10 11 12 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 10 def get_resource(path) get_resource_deep(path,@facade.resource) end |
#paths ⇒ Object
13 14 15 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 13 def paths rpaths(@facade.resource) end |
#visualize_facade(res = @facade.resource, what = '') ⇒ Object
}}}
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 41 def visualize_facade(res=@facade.resource,what='') #{{{ what += res.path puts what res.composition.each do |k,v| puts " #{k.to_s.upcase}:" v.each do |r| puts " #{r.result.class.name.gsub(/[^\:]+::/,'')}: #{r.result.visualize}" r.route.each do |ritem| puts " #{ritem.class.name.gsub(/[^\:]+::/,'')}: #{ritem.visualize}" end unless r.route.nil? end end res.resources.each do |key,r| visualize_facade(r,what + (what == '/' ? '' : '/')) end #}}} end |
#visualize_tiles_and_compositions ⇒ Object
}}}
33 34 35 36 37 38 39 40 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 33 def visualize_tiles_and_compositions #{{{ @tiles.each_with_index do |til,index| puts "### Tile #{index} " + ("#" * 60) til.visualize :composition end #}}} end |
#visualize_tiles_and_layers ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 25 def visualize_tiles_and_layers #{{{ @tiles.each_with_index do |til,index| puts "### Tile #{index} " + ("#" * 60) til.visualize :layers end #}}} end |