Module: Netconf::RPC::Builder
- Defined in:
- lib/net/netconf/rpc.rb
Class Method Summary collapse
-
.method_missing(method, params = nil, attrs = nil) ⇒ Object
autogenerate an <rpc>, converting underscores (_) to hyphens (-) along the way …
Class Method Details
.method_missing(method, params = nil, attrs = nil) ⇒ Object
autogenerate an <rpc>, converting underscores (_) to hyphens (-) along the way …
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 |
# File 'lib/net/netconf/rpc.rb', line 22 def Builder.method_missing( method, params = nil, attrs = nil ) rpc_name = method.to_s.tr('_','-').to_sym if params # build the XML starting at <rpc>, envelope the <method> toplevel element, # and then create name/value elements for each of the additional params. An element # without a value should simply be set to true rpc_nx = Nokogiri::XML::Builder.new { |xml| xml.rpc { xml.send( rpc_name ) { params.each{ |k,v| sym = k.to_s.tr('_','-').to_sym xml.send(sym, (v==true) ? nil : v ) } }} }.doc.root else # -- no params rpc_nx = Nokogiri::XML("<rpc><#{rpc_name}/></rpc>").root end # if a block is given it is used to set the attributes of the toplevel element RPC.add_attributes( rpc_nx.at( rpc_name ), attrs ) if attrs # return the rpc command rpc_nx end |