Sha256: 11422c5019f5fa2815021375e600db28c6aee4d3d50a81364bc5f9ab6272be52
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
module RedisBackedModel class SortedSet require 'date' def initialize(model, model_id, definition) @model = model @model_id = model_id @definition = definition self end def to_redis "zadd|#{key}|#{score}|#{member}" end private attr_accessor :model, :model_id #, :by_attribute, :score_label, :score def definition_keys @definition.keys.first end def definition_values @definition.values.first end def key_by parse_definition(definition_keys)[1] end def key_for parse_definition(definition_keys)[0] end def key_model_name @model.to_s.underscore.pluralize end def key_for_value parse_definition(definition_values)[0] end def member @model_id end def key "#{key_model_name}_for_#{key_for}_by_#{key_by}:#{key_for_value}" end def score score = parse_definition(definition_values)[1] key_by == 'date' ? Date.parse(score).to_time.to_f : score end def parse_definition(string) string.match(/.*\[(\S+)\]/)[1].split('|') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
redis_backed_model-0.0.5 | lib/redis_backed_model/sorted_set.rb |
redis_backed_model-0.0.4 | lib/redis_backed_model/sorted_set.rb |