Module: Ricordami::KeyNamer

Extended by:
KeyNamer
Included in:
KeyNamer
Defined in:
lib/ricordami/key_namer.rb

Instance Method Summary collapse

Instance Method Details

#attributes(model, opts = {}) ⇒ Object



11
12
13
# File 'lib/ricordami/key_namer.rb', line 11

def attributes(model, opts = {})
    "#{model}:att:#{opts[:id]}"
end

#hash_ref(model, opts = {}) ⇒ Object



19
20
21
22
# File 'lib/ricordami/key_namer.rb', line 19

def hash_ref(model, opts = {})
  fields = opts[:fields].join("_") + "_to_id"
  "#{model}:hsh:#{fields}"
end

#index(model, opts = {}) ⇒ Object



24
25
26
27
# File 'lib/ricordami/key_namer.rb', line 24

def index(model, opts = {})
  value = encode(opts[:value])
  "#{model}:idx:#{opts[:field]}:#{value}"
end

#lock(model, opts = {}) ⇒ Object



49
50
51
# File 'lib/ricordami/key_namer.rb', line 49

def lock(model, opts = {})
  "#{model}:val:#{opts[:id]}:_lock"
end

#sequence(model, opts = {}) ⇒ Object



7
8
9
# File 'lib/ricordami/key_namer.rb', line 7

def sequence(model, opts = {})
  "#{model}:seq:#{opts[:type]}"
end

#sort(model, opts = {}) ⇒ Object



53
54
55
# File 'lib/ricordami/key_namer.rb', line 53

def sort(model, opts = {})
  "#{model}:att:*->#{opts[:sort_by]}"
end

#temporary(model) ⇒ Object



44
45
46
47
# File 'lib/ricordami/key_namer.rb', line 44

def temporary(model)
  lock_id = model.redis.incr("#{model}:seq:lock")
  "#{model}:val:_tmp:#{lock_id}"
end

#unique_index(model, opts = {}) ⇒ Object



15
16
17
# File 'lib/ricordami/key_namer.rb', line 15

def unique_index(model, opts = {})
  "#{model}:udx:#{opts[:name]}"
end

#volatile_set(model, opts = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ricordami/key_namer.rb', line 29

def volatile_set(model, opts = {})
  info = opts[:info].dup
  op = info.shift
  if info.empty?
    info = [op]
  else
    info = ["#{op}(#{info.join(",")})"]
  end
  unless opts[:key].nil?
    key = opts[:key].sub("~:#{model}:set:", "")
    info.unshift(key)
  end
  "~:#{model}:set:#{info.join(":")}"
end