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



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

def index_filename
  resolve(@index_filename)
end

#public_pathObject



39
40
41
42
43
44
# File 'lib/indexmap/configuration.rb', line 39

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

  Pathname(value)
end

#sectionsObject



46
47
48
# File 'lib/indexmap/configuration.rb', line 46

def sections
  Array(resolve(@sections))
end

Instance Method Details

#googleObject



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

def google
  @google ||= GoogleConfiguration.new
end

#index_nowObject



35
36
37
# File 'lib/indexmap/configuration.rb', line 35

def index_now
  @index_now ||= IndexNowConfiguration.new
end

#writerObject

Raises:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/indexmap/configuration.rb', line 50

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