Class: Slug
- Inherits:
-
Object
- Object
- Slug
- Includes:
- DataMapper::Resource
- Defined in:
- lib/friendly_id/datamapper_adapter/slug.rb
Overview
A Slug is a unique, human-friendly identifier for a DataMapper model
Class Method Summary collapse
Instance Method Summary collapse
-
#current? ⇒ Boolean
Whether this slug is the most recent of its owner’s slugs.
- #outdated? ⇒ Boolean
- #sluggable ⇒ Object
- #sluggable=(instance) ⇒ Object
- #to_friendly_id ⇒ Object
Class Method Details
.similar_to(slug) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 18 def self.similar_to(slug) all({ :name => slug.name, :scope => slug.scope, :sluggable_type => slug.sluggable_type, :order => [:sequence.asc] }) end |
Instance Method Details
#current? ⇒ Boolean
Whether this slug is the most recent of its owner’s slugs.
28 29 30 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 28 def current? sluggable.slug == self end |
#outdated? ⇒ Boolean
32 33 34 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 32 def outdated? !current? end |
#sluggable ⇒ Object
40 41 42 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 40 def sluggable sluggable_type.get(sluggable_id) end |
#sluggable=(instance) ⇒ Object
44 45 46 47 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 44 def sluggable=(instance) attribute_set(:sluggable_type, instance.class) attribute_set(:sluggable_id, instance.id) end |
#to_friendly_id ⇒ Object
36 37 38 |
# File 'lib/friendly_id/datamapper_adapter/slug.rb', line 36 def to_friendly_id sequence > 1 ? friendly_id_with_sequence : name end |