Class: Riddl::Wrapper::Declaration

Inherits:
WrapperUtils show all
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

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
# 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)
    res = til.base_path(tile.attributes['path'] || '/')
    # res.clean! # for overlapping tiles, each tile gets an empty path TODO
    tile.find("dec:layer").each_with_index do |layer,index|
      apply_to = layer.find("dec:apply-to")
      block = layer.find("dec:block")

      everywhere = layer.attributes['everywhere'] == 'true'
      lname = layer.attributes['name']
      lpath, des = @interfaces[lname]
      desres = des.find("des:resource").first
      if everywhere
        @tiles.map do |til| # extract all currently existing paths for all tiles
          rpaths(til.resource,'').map{|a,b| a}
        end.flatten.uniq.each do |path| # apply current to all paths
          int = Interface.new(lname,path,lpath,"/",des)
          rec = desres.attributes['recursive']
          til.add_description(des,desres,path,index,int,block,rec)
        end
      else
        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|
            int = Interface.new(lname,at.to_s,lpath,"/",des)
            til.add_description(des,desres,at.to_s,index,int,block)
          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

#descriptionObject



21
22
23
# File 'lib/ruby/riddl/wrapper/declaration.rb', line 21

def description
  Riddl::Wrapper.new(@facade.description_xml(@namespaces))
end

#description_xmlObject



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

#pathsObject



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_compositionsObject

}}}



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_layersObject



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