Class: Sitemap::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/sitemap/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Store

Returns a new instance of Store.



7
8
9
10
11
# File 'lib/sitemap/store.rb', line 7

def initialize(options = {})
  self.entries     = []
  self.reset_count = 0
  self.max_entries = options[:max_entries]
end

Instance Attribute Details

#before_reset_callbackObject

Returns the value of attribute before_reset_callback.



5
6
7
# File 'lib/sitemap/store.rb', line 5

def before_reset_callback
  @before_reset_callback
end

#entriesObject

Returns the value of attribute entries.



5
6
7
# File 'lib/sitemap/store.rb', line 5

def entries
  @entries
end

#max_entriesObject

Returns the value of attribute max_entries.



5
6
7
# File 'lib/sitemap/store.rb', line 5

def max_entries
  @max_entries
end

#reset_countObject

Returns the value of attribute reset_count.



5
6
7
# File 'lib/sitemap/store.rb', line 5

def reset_count
  @reset_count
end

Instance Method Details

#<<(entry) ⇒ Object



13
14
15
16
# File 'lib/sitemap/store.rb', line 13

def << entry
  reset! if entries.length >= max_entries
  self.entries << entry
end

#before_reset(&block) ⇒ Object



24
25
26
# File 'lib/sitemap/store.rb', line 24

def before_reset(&block)
  self.before_reset_callback = block
end

#reset!Object



18
19
20
21
22
# File 'lib/sitemap/store.rb', line 18

def reset!
  before_reset_callback.call(entries) if before_reset_callback
  self.entries = []
  self.reset_count += 1
end