Module: HasSlug::SluggableInstanceMethods

Defined in:
lib/has_slug/sluggable_instance_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#found_by_slugObject (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

Returns:

  • (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

Returns:

  • (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.has_slug_options[:slug_column]}_changed?")
  sluggable_changed = self.send("#{self.class.has_slug_options[:attribute]}_changed?")

  scope_changed     = if self.class.has_slug_options[:scope] then self.send("#{self.class.slug_scope_attribute}_changed?")
                                                             else false
                                                             end
  
  (!slug_changed && (self.new_record? || sluggable_changed)) || scope_changed
  
end

#slugObject



16
17
18
# File 'lib/has_slug/sluggable_instance_methods.rb', line 16

def slug
  read_attribute(self.class.has_slug_options[: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.has_slug_options[:slug_column], slug)
end

#sluggableObject



12
13
14
# File 'lib/has_slug/sluggable_instance_methods.rb', line 12

def sluggable
  read_attribute(self.class.has_slug_options[:attribute])
end

#to_paramObject



36
37
38
# File 'lib/has_slug/sluggable_instance_methods.rb', line 36

def to_param
  self.slug || self.id
end