Sha256: c1232336d61f5593f4a08a7c0b07d12565d217b03963fe371595ac44e4d6296c
Contents?: true
Size: 912 Bytes
Versions: 1
Compression:
Stored size: 912 Bytes
Contents
# -*- coding: utf-8 -*- module Redisable module KVSKey def self.included(base) base.extend ClassMethods end module ClassMethods # return model_name:id:field_name def kvs_key(name, options={}) klass_name ||= self.name define_method(name) do |id_=nil| id_ ||= if options[:id] options[:id].call(self) else self.id end KVSKey.join_key(klass_name, id_, name, options[:blank_field]) end define_singleton_method(name) do |id_=nil| id_ ||= options[:id].call(self) KVSKey.join_key(klass_name, id_, name, options[:blank_field]) end end end def self.join_key(klass_name, id, name, is_blank_field) k = "#{klass_name}" k << ":#{id}" if id k << ":#{name}" unless is_blank_field k end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redisable-0.0.2 | lib/redisable/kvs_key.rb |