Class: Hx::Listing::FlatIndex

Inherits:
Object
  • Object
show all
Includes:
Filter
Defined in:
lib/hx/listing/flatindex.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Filter

#each_entry

Methods included from View

#each_entry, #edit_entry

Constructor Details

#initialize(input, options) ⇒ FlatIndex

Returns a new instance of FlatIndex.



39
40
41
42
# File 'lib/hx/listing/flatindex.rb', line 39

def initialize(input, options)
  @input = input
  @index_name = options[:index_name] || "index"
end

Class Method Details

.new(input, options) ⇒ Object



34
35
36
37
# File 'lib/hx/listing/flatindex.rb', line 34

def self.new(input, options)
  listing = super(input, options)
  Listing.apply_options(listing, options)
end

Instance Method Details

#each_entry_path(selector) {|@index_name| ... } ⇒ Object

Yields:

  • (@index_name)


44
45
46
47
# File 'lib/hx/listing/flatindex.rb', line 44

def each_entry_path(selector)
  yield @index_name if selector.accept_path? @index_name
  self
end

#get_entry(path) ⇒ Object

Raises:



49
50
51
52
53
54
55
56
57
58
# File 'lib/hx/listing/flatindex.rb', line 49

def get_entry(path)
  raise NoSuchEntryError, path unless path == @index_name
  index = {'items' => []}
  @input.each_entry(Path::ALL) do |path, entry|
    index['items'] << {'path' => path, 'entry' => entry}
    updated = [entry['updated'], index['updated']].compact.max
    index['updated'] = updated if updated
  end
  index
end