Class: Inferx::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/inferx/adapter.rb

Direct Known Subclasses

Categories, Category

Instance Method Summary collapse

Constructor Details

#initialize(redis, options = {}) ⇒ Adapter

Returns a new instance of Adapter.

Options Hash (options):

  • :namespace (String)

    namespace of keys to be used to Redis

  • :manual (Boolean)

    whether manual save, defaults to false



8
9
10
11
12
13
# File 'lib/inferx/adapter.rb', line 8

def initialize(redis, options = {})
  @redis = redis
  @options = options
  @namespace = options[:namespace]
  @manual = !!options[:manual]
end

Instance Method Details

#categories_keyString

Get the key for access to categories.



25
26
27
# File 'lib/inferx/adapter.rb', line 25

def categories_key
  @categories_key ||= make_categories_key
end

#make_categories_keyString

Make the key for access to categories.



32
33
34
35
36
# File 'lib/inferx/adapter.rb', line 32

def make_categories_key
  parts = %w(inferx categories)
  parts.insert(1, @namespace) if @namespace
  parts.join(':')
end

#make_category_key(category_name) ⇒ String

Make the key for access to scores stored each by word.



42
43
44
# File 'lib/inferx/adapter.rb', line 42

def make_category_key(category_name)
  "#{categories_key}:#{category_name}"
end

#manual?Boolean

Determine if manual save.



18
19
20
# File 'lib/inferx/adapter.rb', line 18

def manual?
  @manual
end

#spawn(klass, *args) ⇒ Object

Spawn an instance of any class.



52
53
54
# File 'lib/inferx/adapter.rb', line 52

def spawn(klass, *args)
  klass.new(@redis, *args, @options)
end