Class: FriendlyId::Status

Inherits:
Object show all
Defined in:
lib/friendly_id/status.rb

Overview

FriendlyId::Status presents information about the status of the id that was used to find the model. This class can be useful for figuring out when to redirect to a new URL.

Direct Known Subclasses

FriendlyId::Slugged::Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Status

Returns a new instance of Status.



14
15
16
# File 'lib/friendly_id/status.rb', line 14

def initialize(options={})
  options.each {|key, value| self.send("#{key}=".to_sym, value)}
end

Instance Attribute Details

#nameObject

The id or name used as the finder argument



9
10
11
# File 'lib/friendly_id/status.rb', line 9

def name
  @name
end

#recordObject

The found result, if any



12
13
14
# File 'lib/friendly_id/status.rb', line 12

def record
  @record
end

Instance Method Details

#best?Boolean

Did the find operation use the best available id?

Returns:

  • (Boolean)


29
30
31
# File 'lib/friendly_id/status.rb', line 29

def best?
  record.friendly_id ? friendly? : true
end

#friendly?Boolean

Did the find operation use a friendly id?

Returns:

  • (Boolean)


19
20
21
# File 'lib/friendly_id/status.rb', line 19

def friendly?
  !! name
end

#numeric?Boolean

Did the find operation use a numeric id?

Returns:

  • (Boolean)


24
25
26
# File 'lib/friendly_id/status.rb', line 24

def numeric?
  !friendly?
end