Class: Riddl::Wrapper::Description::Resource
- Inherits:
-
Object
- Object
- Riddl::Wrapper::Description::Resource
- Defined in:
- lib/ruby/riddl/wrapper/description/resource.rb
Instance Attribute Summary collapse
-
#access_methods ⇒ Object
readonly
}}}.
-
#composition ⇒ Object
readonly
}}}.
-
#custom ⇒ Object
Returns the value of attribute custom.
-
#path ⇒ Object
readonly
}}}.
-
#recursive ⇒ Object
readonly
}}}.
-
#resources ⇒ Object
readonly
}}}.
-
#role ⇒ Object
readonly
}}}.
Instance Method Summary collapse
- #add_access_methods(des, desres, index, interface) ⇒ Object
- #add_custom(desres) ⇒ Object
- #add_websocket(index, interface, custom) ⇒ Object
- #compose! ⇒ Object
- #description_xml(namespaces) ⇒ Object
- #description_xml_string(messages, t) ⇒ Object
-
#description_xml_string_sub(messages, t) ⇒ Object
}}}.
-
#initialize(path = nil, recursive = false) ⇒ Resource
constructor
A new instance of Resource.
-
#remove_access_methods(des, filter) ⇒ Object
TODO add websockets.
Constructor Details
#initialize(path = nil, recursive = false) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 6 def initialize(path=nil,recursive=false) #{{{ @path = path @role = nil @resources = {} @access_methods = {} @composition = {} @recursive = recursive @custom = [] #}}} end |
Instance Attribute Details
#access_methods ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def access_methods @access_methods end |
#composition ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def composition @composition end |
#custom ⇒ Object
Returns the value of attribute custom.
384 385 386 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 384 def custom @custom end |
#path ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def path @path end |
#recursive ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def recursive @recursive end |
#resources ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def resources @resources end |
#role ⇒ Object (readonly)
}}}
383 384 385 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 383 def role @role end |
Instance Method Details
#add_access_methods(des, desres, index, interface) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 18 def add_access_methods(des,desres,index,interface) #{{{ desres.find("des:*[not(name()='resource') and not(name()='websocket') and @in and not(@in='*')]").each do |m| method = m.attributes['method'] || m.qname.name add_request_in_out(index,interface,des,method,m.attributes['in'],m.attributes['out'],m.find('*|text()')) end desres.find("des:*[not(name()='resource') and not(name()='websocket') and @pass and not(@pass='*')]").each do |m| method = m.attributes['method'] || m.qname.name add_request_in_out(index,interface,des,method,m.attributes['pass'],m.attributes['pass'],m.find('*|text()')) end desres.find("des:*[not(name()='resource') and not(name()='websocket') and @transformation]").each do |m| method = m.attributes['method'] || m.qname.name add_request_transform(index,interface,des,method,m.attributes['transformation'],m.find('*|text()')) end desres.find("des:*[not(name()='resource') and not(name()='websocket') and @in and @in='*']").each do |m| method = m.attributes['method'] || m.qname.name add_request_star_out(index,interface,des,method,m.attributes['out'],m.find('*|text()')) end desres.find("des:*[not(name()='resource') and not(name()='websocket') and not(@in)]").each do |m| method = m.attributes['method'] || m.qname.name add_request_star_out(index,interface,des,method,m.attributes['out'],m.find('*|text()')) end desres.find("des:*[not(name()='resource') and not(name()='websocket') and @pass and @pass='*']").each do |m| method = m.attributes['method'] || m.qname.name add_request_pass(index,interface,method,m.find('*|text()')) end desres.find("des:*[not(name()='resource') and name()='websocket']").each do |m| add_websocket(index,interface,m.find('*|text()')) end @role = desres.find("string(@role)") @role = nil if @role.strip == '' #}}} end |
#add_custom(desres) ⇒ Object
52 53 54 55 56 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 52 def add_custom(desres) #{{{ @custom += desres.find("*[not(self::des:*)]").to_a #}}} end |
#add_websocket(index, interface, custom) ⇒ Object
375 376 377 378 379 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 375 def add_websocket(index,interface,custom) @access_methods['websocket'] ||= [] @access_methods['websocket'][index] ||= [] @access_methods['websocket'][index] << WebSocket.new(interface,custom) end |
#compose! ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 101 def compose! #{{{ @access_methods.each do |k,v| ### remove all emtpy layers v.compact! case v.size when 0 when 1 @composition[k] = compose_plain(v[0]) else @composition[k] = compose_layers(k,v) end end #}}} end |
#description_xml(namespaces) ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 318 def description_xml(namespaces) #{{{ namespaces = namespaces.delete_if do |k,n| k =~ /^xmlns\d+$/ || [Riddl::Wrapper::DESCRIPTION, Riddl::Wrapper::DECLARATION, Riddl::Wrapper::XINCLUDE].include?(n) end.map do |k,n| "xmlns:#{k}=\"#{n}\"" end.join(' ') = {} = '' collect = description_xml_string(," " * 4) + description_xml_string_sub(," " * 4) collect = XML::Smart.string("<resource>\n" + collect + " </resource>") names = [] .each do |hash,mess| t = mess.content.dup name = mess.name name += '_' while names.include?(name) collect.find("//@*[.=#{hash}]").each { |e| p e; e.value = name } names << name t.root.attributes['name'] = name << t.root.dump + "\n" end XML::Smart.string("<description #{Riddl::Wrapper::COMMON} #{namespaces}>\n\n" + .gsub(/^/,' ') + "\n " + collect.root.dump + "\n</description>").to_s #}}} end |
#description_xml_string(messages, t) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 282 def description_xml_string(,t) #{{{ result = '' @custom.each do |c| result << c.dump end if @composition.any? @composition.each do |k,v| v.each do |m| result << description_xml_string_analyse(,t,k,m.result) end end else @access_methods.each do |k,v| v.first.each do |m| result << description_xml_string_analyse(,t,k,m) end end end result #}}} end |
#description_xml_string_sub(messages, t) ⇒ Object
}}}
305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 305 def description_xml_string_sub(,t) #{{{ result = '' @resources.each do |k,r| tmp = r.custom.map{ |c| c.dump }.join result << t + "<resource" result << " relative=\"#{k}\"" unless k == "{}" result << (tmp == '' ? "/>\n" : ">\n" + tmp + t + "</resource>\n") end result #}}} end |
#remove_access_methods(des, filter) ⇒ Object
TODO add websockets
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 |
# File 'lib/ruby/riddl/wrapper/description/resource.rb', line 60 def remove_access_methods(des,filter) #{{{ freq = if filter['in'] && filter['in'] != '*' t = [RequestInOut,Riddl::Wrapper::Description::Message.new(des,filter['in'])] t << (filter['out'] ? Riddl::Wrapper::Description::Message.new(des,filter['out']) : nil) elsif filter['pass'] && filter['pass'] != '*' [RequestInOut,Riddl::Wrapper::Description::Message.new(des,filter['pass']),Riddl::Wrapper::Description::Message.new(des,filter['pass'])] elsif filter['in'] && filter['in'] == '*' t = [RequestStarOut] t << (filter['out'] ? Riddl::Wrapper::Description::Message.new(des,filter['out']) : nil) elsif filter['transformation'] [RequestTransformation,Riddl::Wrapper::Description::Transformation.new(des,filter['transformation'])] elsif filter['pass'] && filter['pass'] == '*' [RequestPass] end raise BlockError, "blocking #{filter.inspect} not possible" if freq.nil? if reqs = @access_methods[filter['method']] reqs = reqs.last # current layer reqs.delete_if do |req| if req.class == freq[0] if req.class == RequestInOut # TODO These hash comparisons are maybe too trivial, as we want to catch name="*" parameters if freq[1] && freq[1].hash == req.in.hash && freq[2] && req.out && freq[2].hash == req.out.hash true elsif freq[1] && freq[1].hash == req.in.hash && !freq[2] true end elsif req.class == RequestStarOut true if freq[1] && req.out && freq[1].hash == req.out.hash elsif req.class == RequestTransformation true if freq[1] && freq[1].hash == req.trans.hash elsif req.class == RequestPass true end end end end #}}} end |