Class: Indexmap::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/indexmap/configuration.rb

Constant Summary collapse

VALID_FORMATS =
%i[index single_file].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/indexmap/configuration.rb', line 9

def initialize
  @format = :index
  @index_filename = "sitemap.xml"
end

Instance Attribute Details

#base_urlObject



14
15
16
# File 'lib/indexmap/configuration.rb', line 14

def base_url
  resolve(@base_url)
end

#entriesObject



18
19
20
# File 'lib/indexmap/configuration.rb', line 18

def entries
  Array(resolve(@entries))
end

#formatObject



22
23
24
25
# File 'lib/indexmap/configuration.rb', line 22

def format
  value = resolve(@format)
  value.nil? ? :index : value.to_sym
end

#index_filenameObject



27
28
29
# File 'lib/indexmap/configuration.rb', line 27

def index_filename
  resolve(@index_filename)
end

#public_pathObject



31
32
33
34
35
36
# File 'lib/indexmap/configuration.rb', line 31

def public_path
  value = resolve(@public_path)
  return Pathname("public") if value.nil?

  Pathname(value)
end

#sectionsObject



38
39
40
# File 'lib/indexmap/configuration.rb', line 38

def sections
  Array(resolve(@sections))
end

Instance Method Details

#writerObject

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/indexmap/configuration.rb', line 42

def writer
  raise ConfigurationError, "Indexmap base_url is not configured" if base_url.to_s.strip.empty?

  unless VALID_FORMATS.include?(format)
    raise ConfigurationError, "Indexmap format must be one of: #{VALID_FORMATS.join(", ")}"
  end

  if format == :single_file
    raise ConfigurationError, "Indexmap entries are not configured" if entries.empty?
  elsif sections.empty?
    raise ConfigurationError, "Indexmap sections are not configured" if sections.empty?
  end

  Writer.new(
    entries: entries,
    format: format,
    sections: sections,
    public_path: public_path,
    base_url: base_url,
    index_filename: index_filename
  )
end