Class: Groonga::Context
- Inherits:
-
Object
- Object
- Groonga::Context
- Defined in:
- ext/groonga/rb-grn-context.c,
lib/groonga/context.rb
Overview
groonga全体に渡る情報を管理するオブジェクト。通常のアプリケーションでは1つのコンテキストを作成し、それを利用する。複数のコンテキストを利用する必要はない。
デフォルトで使用されるコンテキストはdefault でアクセスできる。コンテキストを指定できる箇所でコンテキストの指定を省略したり nil
を指定した場合は default が利用される。
また、デフォルトのコンテキストは必要になると暗黙のうちに作成される。そのため、コンテキストを意識することは少ない。
暗黙のうちに作成されるコンテキストにオプションを指定する場合は default_options= を使用する。
Instance Method Summary collapse
-
#create_database(path = nil, &block) ⇒ Object
This is convenience method.
-
#open_database(path, &block) ⇒ Object
path にある既存のデータベースを開く。ブロックを指定した場 合はブロックに開いたデータベースを渡し、ブロックを抜けると きに閉じる。.
-
#register_plugin(name_or_options) ⇒ Object
groongaのプラグインディレクトリにあるプラグイン name を登録する。 path を指定するとプラグインディレクトリ以 外にあるプラグインを登録することができる。.
-
#restore(dumped_commands) {|command, response| ... } ⇒ void
Restore commands dumped by “grndump” command.
-
#select(table, options = {}) ⇒ Object
table から指定した条件にマッチするレコードの値を取得 する。 table はテーブル名かテーブルオブジェクトを指定 する。.
Instance Method Details
#create_database ⇒ Groonga::Database #create_database {|database| ... } ⇒ Object #create_database(path) ⇒ Groonga::Database #create_database(path) {|database| ... } ⇒ Object
This is convenience method. It wraps Database.create for the context.
99 100 101 102 103 104 105 106 |
# File 'lib/groonga/context.rb', line 99 def create_database(path=nil, &block) = {:context => self} if path [:path] = path end Database.create(, &block) end |
#open_database(path, &block) ⇒ Object
path にある既存のデータベースを開く。ブロックを指定した場合はブロックに開いたデータベースを渡し、ブロックを抜けるときに閉じる。
25 26 27 28 29 |
# File 'lib/groonga/context.rb', line 25 def open_database(path, &block) = {:context => self} Database.open(path, , &block) end |
#register_plugin(name_or_options) ⇒ Object
groongaのプラグインディレクトリにあるプラグイン name を登録する。 path を指定するとプラグインディレクトリ以外にあるプラグインを登録することができる。
111 112 113 114 115 116 117 118 119 |
# File 'lib/groonga/context.rb', line 111 def register_plugin() = {:context => self} if .is_a?(String) name = Plugin.register(name, ) else Plugin.register(.merge()) end end |
#restore(dumped_commands) {|command, response| ... } ⇒ void
This method returns an undefined value.
Restore commands dumped by “grndump” command.
If block is given, a response is yielded.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/groonga/context.rb', line 166 def restore(dumped_commands) buffer = "" continued = false dumped_commands.each_line do |line| line = line.chomp case line when /\\\z/ continued = true buffer << $PREMATCH else continued = false buffer << line send(buffer) _, response = receive if block_given? not_shared_command = continued ? buffer.dup : line yield(not_shared_command, response) end buffer.clear end end unless buffer.empty? send(buffer) _, response = receive yield(buffer.dup, response) if block_given? end end |