module ActiveRedis

Public Class Methods

find_by_param_name(param_name) click to toggle source
# File lib/active-redis.rb, line 38
def self.find_by_param_name(param_name)
  first(:param_name => param_name)
end
included(base) click to toggle source
# File lib/active-redis.rb, line 3
def self.included(base)
  base.send(:include, Paperclip::Resource)
  base.send(:include, DataMapper::Resource)
  base.send(:include, Sunspot::ActiveRedis)
  base.send(:extend, ActiveRedisClassMethods)
  base.before :save, :use_param_attribute
  base.after :save, :add_to_index
  base.after :destroy, :remove_from_index
  base.class_eval do
    alias_method :to_param, :new_param
  end
end
model_name() click to toggle source
# File lib/active-redis.rb, line 46
def self.model_name
  @_model_name ||= ActiveModel::Name.new(self)
end
parse_date(hash) click to toggle source
# File lib/active-redis.rb, line 62
def self.parse_date(hash)
  date = DateTime.new(hash["date(1i)"].to_i, hash['date(2i)'].to_i, hash['date(3i)'].to_i, 0, 0)
  return date.to_date
end
parse_date_time(hash) click to toggle source
# File lib/active-redis.rb, line 58
def self.parse_date_time(hash)
  datetime = DateTime.new(hash["datetime(1i)"].to_i, hash['datetime(2i)'].to_i, hash['datetime(3i)'].to_i, hash["datetime(4i)"].to_i, hash["datetime(5i)"].to_i)
end

Public Instance Methods

add_to_index() click to toggle source
# File lib/active-redis.rb, line 16
def add_to_index
  if self.class.is_using_sunspot
    Sunspot.index!(self)
  end
end
find(args) click to toggle source
# File lib/active-redis.rb, line 42
def find(args)
  get(args)
end
new_param() click to toggle source
# File lib/active-redis.rb, line 34
def new_param
  self.class.param_attribute == nil ? id.to_s : self.param_name.to_s
end
persisted?() click to toggle source
# File lib/active-redis.rb, line 54
def persisted?
  new? ? false : true
end
remove_from_index() click to toggle source
# File lib/active-redis.rb, line 22
def remove_from_index
  if self.class.is_using_sunspot
    Sunspot.remove!(self)
  end
end
to_key() click to toggle source
# File lib/active-redis.rb, line 50
def to_key
  new? ? nil : [id]
end
to_s() click to toggle source
# File lib/active-redis.rb, line 67
def to_s
  self.id
end
use_param_attribute() click to toggle source
# File lib/active-redis.rb, line 28
def use_param_attribute
  if self.class.param_attribute != nil
    self.param_name = self.send(self.class.param_attribute).parameterize
  end
end