lib/ass_ole/snippets/shared.rb in ass_ole-snippets-shared-0.1.0 vs lib/ass_ole/snippets/shared.rb in ass_ole-snippets-shared-0.1.2

- old
+ new

@@ -1,13 +1,14 @@ require 'ass_ole/snippets/shared/version' require 'ass_ole' module AssOle module Snippets + # Shared Ole snippets module Shared # Snippet for serialize and deserilize 1C objects to xml - # @note In external runtime it will be cause of a fail in {InfoBase#rm!} + # @note In external runtime it will be cause of a fail in +InfoBase#rm!+ # '... /1Cv8.1CD (Errno::EBUSY)' because external connection # realy keep alive module XMLSerializer is_ole_snippet @@ -25,12 +26,12 @@ # @param obj [WIN32OLE] 1C object # @param xml_file [#path String] target file path # @return +xml_file+ def to_xml_file(obj, xml_file) zxml = newObject 'XMLWriter' - _path = xml_file.respond_to?(:path) ? xml_file.path : xml_file - zxml.openFile(real_win_path(_path)) + path_ = xml_file.respond_to?(:path) ? xml_file.path : xml_file + zxml.openFile(real_win_path(path_)) xDTOSerializer.WriteXML zxml, obj xml_file ensure zxml.close end @@ -47,12 +48,12 @@ # Deserialize 1C object from XML file # @param xml_file [#path String] path to xml file # @return [WIN32OLE] 1C object def from_xml_file(xml_file) zxml = newObject 'XMLReader' - _path = xml_file.respond_to?(:path) ? xml_file.path : xml_file - zxml.openFile(real_win_path(_path)) + path_ = xml_file.respond_to?(:path) ? xml_file.path : xml_file + zxml.openFile(real_win_path(path_)) obj = xDTOSerializer.ReadXml zxml obj ensure zxml.close end @@ -62,15 +63,15 @@ module Query is_ole_snippet # Returns 1C query object # @return [WIN32OLE] - def query(text, temp_tables_manager = nil, **params) + def query(text, temp_tables_manager_ = nil, **params) q = newObject('Query', text) - q.TempTablesManager = temp_tables_manager || temp_tables_manager() - params.each do |k,v| - q.SetParameter(k.to_s,v) + q.TempTablesManager = temp_tables_manager_ || temp_tables_manager + params.each do |k, v| + q.SetParameter(k.to_s, v) end q end # Returns 1C TempTablesManager @@ -82,24 +83,31 @@ # Do in transaction wrapper module Transaction is_ole_snippet - # @fail [RuntimeError] if nested transaction + # rubocop:disable Metrics/MethodLength + + # @raise [RuntimeError] if nested transaction def do_in_transaction(&block) fail ArgumentError, 'Block require' unless block_given? fail 'Nested transaction is mindless in 1C runtime' if\ transactionActive begin beginTransAction r = instance_eval(&block) commitTransAction r - rescue Exception => e + rescue StandardError => e rollBackTransaction - fail e + raise e end end + + # rubocop:enable Metrics/MethodLength end + + require 'ass_ole/snippets/shared/mapped' + require 'ass_ole/snippets/shared/array' end end end