Class: SiteMaps::Configuration
- Inherits:
-
Object
- Object
- SiteMaps::Configuration
show all
- Defined in:
- lib/site_maps/configuration.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
41
42
43
44
45
46
47
48
49
|
# File 'lib/site_maps/configuration.rb', line 41
def initialize(**options)
default_attributes.merge(options).each do |key, value|
send(:"#{key}=", value)
rescue NoMethodError
raise ConfigurationError, <<~ERROR
Unknown configuration option: #{key}
ERROR
end
end
|
Class Method Details
.attribute(name, default: nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/site_maps/configuration.rb', line 10
def attribute(name, default: nil)
@attributes ||= {}
@attributes[name] = default
unless method_defined?(name)
define_method(name) do
instance_variable_get(:"@#{name}")
end
end
unless method_defined?(:"#{name}=")
define_method(:"#{name}=") do |value|
instance_variable_set(:"@#{name}", value)
end
end
unless method_defined?(:"#{name}?")
define_method(:"#{name}?") do
!!send(name)
end
end
end
|
.attributes ⇒ Object
6
7
8
|
# File 'lib/site_maps/configuration.rb', line 6
def attributes
@attributes || {}
end
|
.inherited(subclass) ⇒ Object
33
34
35
|
# File 'lib/site_maps/configuration.rb', line 33
def inherited(subclass)
subclass.instance_variable_set(:@attributes, attributes.dup)
end
|
Instance Method Details
#base_uri ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/site_maps/configuration.rb', line 65
def base_uri
::URI.parse(url).tap do |uri|
uri.path = ""
uri.query = nil
uri.fragment = nil
end
end
|
#becomes(klass, **options) ⇒ Object
51
52
53
|
# File 'lib/site_maps/configuration.rb', line 51
def becomes(klass, **options)
klass.new(**to_h, **options)
end
|
#fetch_sitemap_index_links ⇒ Object
#local_sitemap_path ⇒ Object
73
74
75
76
|
# File 'lib/site_maps/configuration.rb', line 73
def local_sitemap_path
filename = ::File.basename(url)
Pathname.new(directory).join(filename)
end
|
#remote_sitemap_directory ⇒ Object
91
92
93
94
95
|
# File 'lib/site_maps/configuration.rb', line 91
def remote_sitemap_directory
path = ::URI.parse(url).path
path = path[1..-1] if path.start_with?("/")
path.split("/")[0..-2].join("/")
end
|
#to_h ⇒ Object
55
56
57
58
59
|
# File 'lib/site_maps/configuration.rb', line 55
def to_h
instance_variables.each_with_object({}) do |var, hash|
hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
end
end
|
#url ⇒ Object
61
62
63
|
# File 'lib/site_maps/configuration.rb', line 61
def url
@url || validate_url!
end
|