[Groonga-commit] groonga/fluent-plugin-droonga [master] Extract common create and close context code

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Apr 4 14:54:04 JST 2013


Kouhei Sutou	2013-04-04 14:54:04 +0900 (Thu, 04 Apr 2013)

  New Revision: badf11498eb38beaa6b104e0f51fb3eb3b27a331
  https://github.com/groonga/fluent-plugin-droonga/commit/badf11498eb38beaa6b104e0f51fb3eb3b27a331

  Message:
    Extract common create and close context code
    
    Before:
    
        context = Context.new
        ...
        context.close
    
    After:
    
        create_context do |context|
          ...
        end

  Modified files:
    lib/fluent/plugin/out_droonga.rb

  Modified: lib/fluent/plugin/out_droonga.rb (+13 -4)
===================================================================
--- lib/fluent/plugin/out_droonga.rb    2013-04-03 19:02:21 +0900 (1baea60)
+++ lib/fluent/plugin/out_droonga.rb    2013-04-04 14:54:04 +0900 (6979c43)
@@ -83,21 +83,30 @@ module Fluent
     def ensure_database
       return if File.exist?(@database)
       FileUtils.mkdir_p(File.dirname(@database))
-      context = Groonga::Context.new
+      create_context do |context|
       context.create_database(@database) do
       end
-      context.close
+      end
     end
 
     def ensure_queue
-      context = Groonga::Context.new
+      create_context do |context|
       context.open_database(@database) do
         Groonga::Schema.define(:context => context) do |schema|
           schema.create_table(@queue_name, :type => :array) do
           end
         end
       end
-      context.close
+      end
+    end
+
+    def create_context
+      context = Groonga::Context.new
+      begin
+        yield(context)
+      ensure
+        context.close
+      end
     end
 
     def load_handlers
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index