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
13
14
# File 'lib/indexmap/configuration.rb', line 9

def initialize
  @format = :index
  @index_filename = "sitemap.xml"
  @after_create_callbacks = []
  @outputs = {}
end

Instance Attribute Details

#base_urlObject



16
17
18
# File 'lib/indexmap/configuration.rb', line 16

def base_url
  resolve(@base_url)
end

#entriesObject



20
21
22
# File 'lib/indexmap/configuration.rb', line 20

def entries
  Array(resolve(@entries))
end

#formatObject



24
25
26
27
# File 'lib/indexmap/configuration.rb', line 24

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

#index_filenameObject



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

def index_filename
  resolve(@index_filename)
end

#public_pathObject



41
42
43
44
45
46
# File 'lib/indexmap/configuration.rb', line 41

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

  Pathname(value)
end

#sectionsObject



48
49
50
# File 'lib/indexmap/configuration.rb', line 48

def sections
  Array(resolve(@sections))
end

Instance Method Details

#after_create(&block) ⇒ Object

Raises:

  • (ArgumentError)


63
64
65
66
67
# File 'lib/indexmap/configuration.rb', line 63

def after_create(&block)
  raise ArgumentError, "after_create requires a block" unless block

  @after_create_callbacks << block
end

#googleObject



29
30
31
# File 'lib/indexmap/configuration.rb', line 29

def google
  @google ||= GoogleConfiguration.new
end

#index_nowObject



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

def index_now
  @index_now ||= IndexNowConfiguration.new
end

#output(name) {|output| ... } ⇒ Object

Yields:



52
53
54
55
56
# File 'lib/indexmap/configuration.rb', line 52

def output(name)
  output = output_for(name)
  yield(output) if block_given?
  output
end

#output_for(name = :default) ⇒ Object



58
59
60
61
# File 'lib/indexmap/configuration.rb', line 58

def output_for(name = :default)
  normalized_name = name.to_sym
  @outputs[normalized_name] ||= Output.new(configuration: self)
end

#run_after_create_callbacksObject



69
70
71
# File 'lib/indexmap/configuration.rb', line 69

def run_after_create_callbacks
  @after_create_callbacks.each(&:call)
end

#writerObject



73
74
75
# File 'lib/indexmap/configuration.rb', line 73

def writer
  output_for(:default).writer
end