Commits

Yuya Nishihara committed ad4fd80

introduced switch_kcode helper method

  • Participants
  • Parent commits 4e04a5d

Comments (0)

Files changed (1)

lib/tasks/import_kagemai_reports.rake

       Kagemai::Config.initialize(KAGEMAI_ROOT, "#{KAGEMAI_ROOT}/kagemai.conf")
 
       # due to `premature end of regular expression' error
-      orig_kcode = $KCODE
-      $KCODE = 'EUC-JP'
-      require 'kagemai/fold'
-      $KCODE = orig_kcode
+      switch_kcode('EUC-JP') { require 'kagemai/fold' }
 
       require 'kagemai/bts'
       require 'kagemai/project'
     def self.encode(text)
       @iconv.iconv text
     end
+
+    # do something in another $KCODE
+    def self.switch_kcode(encoding)
+      orig_kcode = $KCODE
+      $KCODE = encoding
+      begin
+        ret = yield
+      ensure
+        $KCODE = orig_kcode
+      end
+      ret
+    end
   end
 
   KagemaiImport.initialize()