Class: Soulheart::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/soulheart/base.rb

Direct Known Subclasses

Loader, Matcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#normalize, #prefixes_for_phrase

Instance Attribute Details

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/soulheart/base.rb', line 5

def type
  @type
end

Instance Method Details

#base_idObject



15
16
17
# File 'lib/soulheart/base.rb', line 15

def base_id
  ENV['RACK_ENV'] != 'test' ? 'soulheart:' : 'soulheart_test:'
end

#cache_id(type = 'all') ⇒ Object



52
53
54
# File 'lib/soulheart/base.rb', line 52

def cache_id(type = 'all')
  "#{base_id}cache:#{type}:"
end

#cache_lengthObject



11
12
13
# File 'lib/soulheart/base.rb', line 11

def cache_length
  10 * 60 # Setting to 10 minutes, but making it possible to edit down the line
end

#categories_idObject



36
37
38
# File 'lib/soulheart/base.rb', line 36

def categories_id
  "#{base_id}categories:"
end

#category_combosObject



32
33
34
# File 'lib/soulheart/base.rb', line 32

def category_combos
  redis.smembers(category_combos_id)
end

#category_combos_idObject



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

def category_combos_id
  "#{base_id}category_combos:"
end

#category_id(name = 'all') ⇒ Object



40
41
42
# File 'lib/soulheart/base.rb', line 40

def category_id(name = 'all')
  "#{categories_id}#{name}:"
end

#no_query_id(category = category_id) ⇒ Object



44
45
46
# File 'lib/soulheart/base.rb', line 44

def no_query_id(category = category_id)
  "all:#{category}"
end

#redisObject



7
8
9
# File 'lib/soulheart/base.rb', line 7

def redis
  Soulheart.redis
end

#results_hashes_idObject



48
49
50
# File 'lib/soulheart/base.rb', line 48

def results_hashes_id
  "#{base_id}database:"
end

#set_category_combos_arrayObject



19
20
21
22
23
24
25
26
# File 'lib/soulheart/base.rb', line 19

def set_category_combos_array
  redis.expire category_combos_id, 0
  ar = redis.smembers(categories_id).map { |c| normalize(c) }.uniq.sort
  ar = 1.upto(ar.size).flat_map { |n| ar.combination(n).map { |el| el.join('') } }
  ar.last.replace('all')
  redis.sadd category_combos_id, ar
  ar
end