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.
48
49
50
51
52
53
54
55
56
|
# File 'lib/site_maps/configuration.rb', line 48
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
72
73
74
75
76
77
78
|
# File 'lib/site_maps/configuration.rb', line 72
def base_uri
::URI.parse(url).tap do |uri|
uri.path = ""
uri.query = nil
uri.fragment = nil
end
end
|
#becomes(klass, **options) ⇒ Object
58
59
60
|
# File 'lib/site_maps/configuration.rb', line 58
def becomes(klass, **options)
klass.new(**to_h, **options)
end
|
#fetch_sitemap_index_links ⇒ Object
#local_sitemap_path ⇒ Object
80
81
82
83
|
# File 'lib/site_maps/configuration.rb', line 80
def local_sitemap_path
filename = ::File.basename(url)
Pathname.new(directory).join(filename)
end
|
#remote_sitemap_directory ⇒ Object
98
99
100
101
102
|
# File 'lib/site_maps/configuration.rb', line 98
def remote_sitemap_directory
path = ::URI.parse(url).path
path = path[1..] if path.start_with?("/")
path.split("/")[0..-2].join("/")
end
|
#to_h ⇒ Object
62
63
64
65
66
|
# File 'lib/site_maps/configuration.rb', line 62
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
68
69
70
|
# File 'lib/site_maps/configuration.rb', line 68
def url
@url || validate_url!
end
|