Module: ActiveRedis

Defined in:
lib/active-redis.rb

Defined Under Namespace

Modules: ActiveRedisClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_param_name(param_name) ⇒ Object



38
39
40
# File 'lib/active-redis.rb', line 38

def self.find_by_param_name(param_name)
  first(:param_name => param_name)
end

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# 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_nameObject



46
47
48
# File 'lib/active-redis.rb', line 46

def self.model_name
  @_model_name ||= ActiveModel::Name.new(self)
end

.parse_date(hash) ⇒ Object



62
63
64
65
# 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) ⇒ Object



58
59
60
# 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

Instance Method Details

#add_to_indexObject



16
17
18
19
20
# File 'lib/active-redis.rb', line 16

def add_to_index
  if self.class.is_using_sunspot
    Sunspot.index!(self)
  end
end

#find(args) ⇒ Object



42
43
44
# File 'lib/active-redis.rb', line 42

def find(args)
  get(args)
end

#new_paramObject



34
35
36
# 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?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/active-redis.rb', line 54

def persisted?
  new? ? false : true
end

#remove_from_indexObject



22
23
24
25
26
# File 'lib/active-redis.rb', line 22

def remove_from_index
  if self.class.is_using_sunspot
    Sunspot.remove!(self)
  end
end

#to_keyObject



50
51
52
# File 'lib/active-redis.rb', line 50

def to_key
  new? ? nil : [id]
end

#to_sObject



67
68
69
# File 'lib/active-redis.rb', line 67

def to_s
  self.id
end

#use_param_attributeObject



28
29
30
31
32
# 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