Sha256: bec3728042e6dcd75ebb17bbe258fb000904ebeabc089eb0fa5d22a69660450d

Contents?: true

Size: 1.3 KB

Versions: 24

Compression:

Stored size: 1.3 KB

Contents

module Groonga
  class Command
    @@classes = {}
    class << self
      def register_class(name, klass)
        @@classes[name] = klass
      end

      def find_class(name)
        @@classes[name]
      end
    end

    private
    def context
      @context ||= Context.instance
    end

    def writer
      @writer ||= context.writer
    end

    def query_logger
      @query_logger ||= context.query_logger
    end

    def cache_key(input)
      nil
    end

    def cache_output(key, options={})
      if key.nil?
        yield
      else
        cache = Cache.current
        cached_value = cache.fetch(key)
        if cached_value
          context.output = cached_value
          cache.unref(key)
          query_logger.log(:cache, ":", "cache(#{cached_value.bytesize})")
        else
          yield
          cache.update(key, context.output) if options[:update]
        end
      end
    end

    def run_internal(input)
      begin
        options = {
          :update => (input["cache"] != "no"),
        }
        cache_output(cache_key(input), options) do
          run_body(input)
        end
      rescue GroongaError => groonga_error
        context.set_groonga_error(groonga_error)
        nil
      rescue => error
        context.record_error(:command_error, error)
        nil
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rroonga-6.1.3-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.1.3-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.1.0-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.1.0-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.9-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.9-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.7-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.7-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.5-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.5-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.4-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.4-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.2-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.2-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.0-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-6.0.0-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-5.1.1-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-5.1.1-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-5.0.9-x86-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb
rroonga-5.0.9-x64-mingw32 vendor/local/lib/groonga/scripts/ruby/command.rb