Module: Groovy

Defined in:
lib/groovy/schema.rb,
lib/groovy/model.rb,
lib/groovy/query.rb,
lib/groovy/types.rb,
lib/groovy/vector.rb,
lib/groovy/version.rb,
lib/groovy/middleware.rb,
lib/groovy.rb

Overview

require File.expand_path(File.dirname(__FILE__)) + ‘/types’

Defined Under Namespace

Modules: Model, Types, Utils Classes: ContextAlreadyClosed, ContextNotFound, Error, MemoryPoolMiddleware, Query, RecordNotPersisted, Schema, Vector

Constant Summary collapse

VERSION =
'0.7.0'.freeze

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



24
25
26
# File 'lib/groovy.rb', line 24

def [](name)
  contexts[name.to_sym]
end

.close(name = :default) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/groovy.rb', line 48

def close(name = :default)
  ctx = contexts[name.to_sym] or raise ContextNotFound.new(name)
  contexts.delete(name.to_sym)
  ctx.close
rescue Groonga::Closed => e
  raise ContextAlreadyClosed
end

.contextsObject



20
21
22
# File 'lib/groovy.rb', line 20

def contexts
  @contexts ||= {}
end

.first_context_nameObject



28
29
30
# File 'lib/groovy.rb', line 28

def first_context_name
  contexts.keys.first
end

.loggerObject



60
61
62
# File 'lib/groovy.rb', line 60

def logger
  @logger ||= Logger.new(STDOUT)
end

.logger=(obj) ⇒ Object



56
57
58
# File 'lib/groovy.rb', line 56

def logger=(obj)
  @logger = obj
end

.modelsObject



16
17
18
# File 'lib/groovy/model.rb', line 16

def self.models
  @models ||= {}
end

.open(db_path, name = :default, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/groovy.rb', line 32

def open(db_path, name = :default, opts = {})
  unless db_path.is_a?(String)
    raise ArgumentError, "Invalid db_path: #{db_path}"
  end

  if contexts[name.to_sym]
    raise ArgumentError, "Context already defined: #{name}"
  end

  contexts[name.to_sym] = if name == :default
    Groonga::Context.default.tap { |ctx| open_or_create_db(ctx, db_path) }
  else
    init_context(db_path)
  end
end