Module: HasSlug::SluggableInstanceMethods
- Defined in:
- lib/has_slug/sluggable_instance_methods.rb
Instance Attribute Summary collapse
-
#found_by_slug ⇒ Object
readonly
Returns the value of attribute found_by_slug.
Instance Method Summary collapse
- #found_by_slug! ⇒ Object
- #found_by_slug? ⇒ Boolean
- #new_slug_needed? ⇒ Boolean
- #slug ⇒ Object
- #slug=(slug) ⇒ Object
- #sluggable ⇒ Object
- #to_param ⇒ Object
Instance Attribute Details
#found_by_slug ⇒ Object (readonly)
Returns the value of attribute found_by_slug.
2 3 4 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 2 def found_by_slug @found_by_slug end |
Instance Method Details
#found_by_slug! ⇒ Object
4 5 6 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 4 def found_by_slug! @found_by_slug = true end |
#found_by_slug? ⇒ Boolean
8 9 10 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 8 def found_by_slug? @found_by_slug end |
#new_slug_needed? ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 24 def new_slug_needed? slug_changed = self.send("#{self.class.[:slug_column]}_changed?") sluggable_changed = self.send("#{self.class.[:attribute]}_changed?") scope_changed = if self.class.[:scope] then self.send("#{self.class.slug_scope_attribute}_changed?") else false end (!slug_changed && (self.new_record? || sluggable_changed)) || scope_changed end |
#slug ⇒ Object
16 17 18 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 16 def slug read_attribute(self.class.[:slug_column]) end |
#slug=(slug) ⇒ Object
20 21 22 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 20 def slug=(slug) write_attribute(self.class.[:slug_column], slug) end |
#sluggable ⇒ Object
12 13 14 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 12 def sluggable read_attribute(self.class.[:attribute]) end |
#to_param ⇒ Object
36 37 38 |
# File 'lib/has_slug/sluggable_instance_methods.rb', line 36 def to_param self.slug || self.id end |