Class: Redirect

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Validations, RedisRedirect::Persistence
Defined in:
lib/redis-redirect/redirect.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RedisRedirect::Persistence

#destroy, #destroy!, #destroyed?, #new_record?, #persisted?, #save, #save!, #update_attributes, #update_attributes!

Constructor Details

#initialize(options = {}) ⇒ Redirect

Returns a new instance of Redirect.



25
26
27
28
29
# File 'lib/redis-redirect/redirect.rb', line 25

def initialize(options = {})
  @source = options[:source]
  @target = options[:target]
  @destroyed = false
end

Instance Attribute Details

#destroyedObject (readonly)

Returns the value of attribute destroyed.



10
11
12
# File 'lib/redis-redirect/redirect.rb', line 10

def destroyed
  @destroyed
end

#new_recordObject (readonly)

Returns the value of attribute new_record.



10
11
12
# File 'lib/redis-redirect/redirect.rb', line 10

def new_record
  @new_record
end

#sourceObject

Returns the value of attribute source.



9
10
11
# File 'lib/redis-redirect/redirect.rb', line 9

def source
  @source
end

#targetObject

Returns the value of attribute target.



9
10
11
# File 'lib/redis-redirect/redirect.rb', line 9

def target
  @target
end

Class Method Details

.allObject

this is really slow, blocks redis, should find alternative but it should also only be used administratively



14
15
16
17
18
# File 'lib/redis-redirect/redirect.rb', line 14

def self.all
  RedisRedirect.redis.keys.map do |x|
    self.new(:source => x, :target => RedisRedirect.redis.get(x) )
  end
end

.find(source) ⇒ Object



20
21
22
23
# File 'lib/redis-redirect/redirect.rb', line 20

def self.find(source)
  target = RedisRedirect.redis.get(source)
  target ? self.new(:source => source, :target => target) : nil
end

Instance Method Details

#idObject



35
36
37
# File 'lib/redis-redirect/redirect.rb', line 35

def id
  nil
end

#inspectObject



31
32
33
# File 'lib/redis-redirect/redirect.rb', line 31

def inspect
  "#<Redirect source: #{source.inspect}, target: #{target.inspect}>"
end

#to_keyObject

MODULE ActiveRecord::AttributeMethods::PrimaryKey



44
45
46
# File 'lib/redis-redirect/redirect.rb', line 44

def to_key
  [to_param]
end

#to_paramObject



39
40
41
# File 'lib/redis-redirect/redirect.rb', line 39

def to_param
  source ? source.gsub('/', '%2F') : nil
end