Class: Slugable::SlugBuilder::CachingTreeAncestry

Inherits:
TreeAncestry
  • Object
show all
Defined in:
lib/slugable/slug_builder/caching_tree_ancestry.rb

Instance Attribute Summary collapse

Attributes inherited from TreeAncestry

#formatter, #slug_column

Instance Method Summary collapse

Methods inherited from TreeAncestry

#to_slug_was, #to_slug_will

Constructor Details

#initialize(options) ⇒ CachingTreeAncestry

Returns a new instance of CachingTreeAncestry.



6
7
8
9
# File 'lib/slugable/slug_builder/caching_tree_ancestry.rb', line 6

def initialize(options)
  super
  @cache = options.fetch(:cache)
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



4
5
6
# File 'lib/slugable/slug_builder/caching_tree_ancestry.rb', line 4

def cache
  @cache
end

Instance Method Details

#to_slug(record) ⇒ Object



11
12
13
# File 'lib/slugable/slug_builder/caching_tree_ancestry.rb', line 11

def to_slug(record)
  record.path_ids.map{ |id| cache.read_slug(slug_column, id) }.select(&:present?)
end