Class: Redirect
- Inherits:
-
Object
- Object
- Redirect
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Validations, RedisRedirect::Persistence
- Defined in:
- lib/redis-redirect/redirect.rb
Instance Attribute Summary collapse
-
#destroyed ⇒ Object
readonly
Returns the value of attribute destroyed.
-
#new_record ⇒ Object
readonly
Returns the value of attribute new_record.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
-
.all ⇒ Object
this is really slow, blocks redis, should find alternative but it should also only be used administratively.
- .find(source) ⇒ Object
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(options = {}) ⇒ Redirect
constructor
A new instance of Redirect.
- #inspect ⇒ Object
-
#to_key ⇒ Object
MODULE ActiveRecord::AttributeMethods::PrimaryKey.
- #to_param ⇒ Object
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( = {}) @source = [:source] @target = [:target] @destroyed = false end |
Instance Attribute Details
#destroyed ⇒ Object (readonly)
Returns the value of attribute destroyed.
10 11 12 |
# File 'lib/redis-redirect/redirect.rb', line 10 def destroyed @destroyed end |
#new_record ⇒ Object (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 |
#source ⇒ Object
Returns the value of attribute source.
9 10 11 |
# File 'lib/redis-redirect/redirect.rb', line 9 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
9 10 11 |
# File 'lib/redis-redirect/redirect.rb', line 9 def target @target end |
Class Method Details
.all ⇒ Object
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
#id ⇒ Object
35 36 37 |
# File 'lib/redis-redirect/redirect.rb', line 35 def id nil end |
#inspect ⇒ Object
31 32 33 |
# File 'lib/redis-redirect/redirect.rb', line 31 def inspect "#<Redirect source: #{source.inspect}, target: #{target.inspect}>" end |
#to_key ⇒ Object
MODULE ActiveRecord::AttributeMethods::PrimaryKey
44 45 46 |
# File 'lib/redis-redirect/redirect.rb', line 44 def to_key [to_param] end |
#to_param ⇒ Object
39 40 41 |
# File 'lib/redis-redirect/redirect.rb', line 39 def to_param source ? source.gsub('/', '%2F') : nil end |