ktlacaelel-sitemaps 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/configuration.rb +32 -1
- data/lib/generator.rb +2 -2
- data/sitemaps.gemspec +5 -1
- data/test/configuration_test.rb +52 -16
- data/test/data/generator_with_http_configuration_file.yml +11 -0
- data/test/data/generator_with_port_configuration_file.yml +11 -0
- data/test/data/no_domain_configuration_file.yml +3 -1
- data/test/data/no_dump_dir_configuration_file.yml +3 -1
- data/test/data/no_generator_configuration_file.yml +2 -0
- data/test/data/no_port_configuration_file.yml +9 -0
- data/test/data/no_targets_configuration_file.yml +3 -1
- data/test/data/no_timeout_configuration_file.yml +8 -0
- data/test/data/valid_configuration_file.yml +37 -5
- data/test/data/valid_configuration_file2.yml +4 -1
- data/test/generator_test.rb +1 -1
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/configuration.rb
CHANGED
@@ -2,7 +2,7 @@ module Sitemaps
|
|
2
2
|
|
3
3
|
class Configuration
|
4
4
|
|
5
|
-
attr_reader :generator, :domain, :targets, :dump_dir
|
5
|
+
attr_reader :generator, :domain, :targets, :dump_dir, :generator_port, :generator_timeout
|
6
6
|
|
7
7
|
def initialize(yaml_file)
|
8
8
|
@yaml_file = yaml_file
|
@@ -14,6 +14,8 @@ module Sitemaps
|
|
14
14
|
def validate!
|
15
15
|
validate_file!
|
16
16
|
validate_generator!
|
17
|
+
validate_generator_port!
|
18
|
+
validate_generator_timeout!
|
17
19
|
validate_domain!
|
18
20
|
validate_dump_dir!
|
19
21
|
validate_targets!
|
@@ -33,6 +35,26 @@ module Sitemaps
|
|
33
35
|
@configuration = @configuration['configuration']
|
34
36
|
end
|
35
37
|
|
38
|
+
def validate_generator_timeout!
|
39
|
+
unless @configuration.keys.include? 'generator_timeout'
|
40
|
+
raise InvalidConfigurationError.new('Missing generator timeout in config')
|
41
|
+
end
|
42
|
+
unless @configuration['generator_timeout'].is_a? Fixnum
|
43
|
+
raise InvalidConfigurationError.new('Please specify a generator timeout')
|
44
|
+
end
|
45
|
+
@generator_timeout = @configuration['generator_timeout']
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate_generator_port!
|
49
|
+
unless @configuration.keys.include? 'generator_port'
|
50
|
+
raise InvalidConfigurationError.new('Missing generator port in config')
|
51
|
+
end
|
52
|
+
unless @configuration['generator_port'].is_a? Fixnum
|
53
|
+
raise InvalidConfigurationError.new('Please specify a generator port')
|
54
|
+
end
|
55
|
+
@generator_port = @configuration['generator_port']
|
56
|
+
end
|
57
|
+
|
36
58
|
def validate_generator!
|
37
59
|
unless @configuration.keys.include? 'generator'
|
38
60
|
raise InvalidConfigurationError.new('Missing generator in config')
|
@@ -40,6 +62,15 @@ module Sitemaps
|
|
40
62
|
if @configuration['generator'].nil? || @configuration['generator'] == ''
|
41
63
|
raise InvalidConfigurationError.new('Please specify a generator')
|
42
64
|
end
|
65
|
+
unless @configuration['generator'].is_a? String
|
66
|
+
raise InvalidConfigurationError.new('Generator is not a string')
|
67
|
+
end
|
68
|
+
if @configuration['generator'] =~ /^http/
|
69
|
+
raise InvalidConfigurationError.new('Do not prefix generator with http')
|
70
|
+
end
|
71
|
+
if @configuration['generator'] =~ /:\d+$/
|
72
|
+
raise InvalidConfigurationError.new('Do not sufix generator with port!')
|
73
|
+
end
|
43
74
|
@generator = @configuration['generator']
|
44
75
|
end
|
45
76
|
|
data/lib/generator.rb
CHANGED
@@ -68,8 +68,8 @@ module Sitemaps
|
|
68
68
|
|
69
69
|
def download!
|
70
70
|
ensure_dump_dir
|
71
|
-
Net::HTTP.start(@configuration.generator,
|
72
|
-
http.read_timeout =
|
71
|
+
Net::HTTP.start(@configuration.generator, @configuration.generator_port) do |http|
|
72
|
+
http.read_timeout = @configuration.generator_timeout
|
73
73
|
@configuration.targets.each do |target|
|
74
74
|
store_downloaded_data target, http.get(target).body
|
75
75
|
end
|
data/sitemaps.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sitemaps}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kazuyoshi tlacaelel"]
|
@@ -36,11 +36,15 @@ Gem::Specification.new do |s|
|
|
36
36
|
"sitemaps.gemspec",
|
37
37
|
"test/configuration_test.rb",
|
38
38
|
"test/data/empty_configuration_file.yml",
|
39
|
+
"test/data/generator_with_http_configuration_file.yml",
|
40
|
+
"test/data/generator_with_port_configuration_file.yml",
|
39
41
|
"test/data/invalid_configuration_file.yml",
|
40
42
|
"test/data/no_domain_configuration_file.yml",
|
41
43
|
"test/data/no_dump_dir_configuration_file.yml",
|
42
44
|
"test/data/no_generator_configuration_file.yml",
|
45
|
+
"test/data/no_port_configuration_file.yml",
|
43
46
|
"test/data/no_targets_configuration_file.yml",
|
47
|
+
"test/data/no_timeout_configuration_file.yml",
|
44
48
|
"test/data/valid_configuration_file.yml",
|
45
49
|
"test/data/valid_configuration_file2.yml",
|
46
50
|
"test/generator_test.rb",
|
data/test/configuration_test.rb
CHANGED
@@ -3,13 +3,17 @@ require 'test_helper'
|
|
3
3
|
class ConfigurationTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@
|
7
|
-
@invalid
|
8
|
-
@empty = 'test/data/empty_configuration_file.yml'
|
9
|
-
@no_generator = 'test/data/no_generator_configuration_file.yml'
|
6
|
+
@empty = 'test/data/empty_configuration_file.yml'
|
7
|
+
@invalid = 'test/data/invalid_configuration_file.yml'
|
10
8
|
@no_domain = 'test/data/no_domain_configuration_file.yml'
|
11
|
-
@no_targets = 'test/data/no_targets_configuration_file.yml'
|
12
9
|
@no_dump_dir = 'test/data/no_dump_dir_configuration_file.yml'
|
10
|
+
@no_generator = 'test/data/no_generator_configuration_file.yml'
|
11
|
+
@no_port = 'test/data/no_port_configuration_file.yml'
|
12
|
+
@no_targets = 'test/data/no_targets_configuration_file.yml'
|
13
|
+
@no_timeout = 'test/data/no_timeout_configuration_file.yml'
|
14
|
+
@gen_n_port = 'test/data/generator_with_port_configuration_file.yml'
|
15
|
+
@gen_n_http = 'test/data/generator_with_http_configuration_file.yml'
|
16
|
+
@valid = 'test/data/valid_configuration_file.yml'
|
13
17
|
end
|
14
18
|
|
15
19
|
# ============================================================================
|
@@ -17,8 +21,8 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
17
21
|
# ============================================================================
|
18
22
|
|
19
23
|
should 'check if configuration file exists' do
|
20
|
-
assert_raise
|
21
|
-
assert_raise
|
24
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new('a') }
|
25
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(nil) }
|
22
26
|
end
|
23
27
|
|
24
28
|
should 'load a configuration file' do
|
@@ -29,20 +33,44 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
29
33
|
# MISSING PARAMETERS
|
30
34
|
# ============================================================================
|
31
35
|
|
32
|
-
should '
|
33
|
-
assert_raise
|
36
|
+
should 'raise an error when generator is not given' do
|
37
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_generator) }
|
38
|
+
end
|
39
|
+
|
40
|
+
should 'raise an error when generator port is not given' do
|
41
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_port) }
|
42
|
+
end
|
43
|
+
|
44
|
+
should 'raise an error when generator timeout is not given' do
|
45
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_timeout) }
|
34
46
|
end
|
35
47
|
|
36
|
-
should '
|
37
|
-
assert_raise
|
48
|
+
should 'raise an error when domain is not given' do
|
49
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_domain) }
|
38
50
|
end
|
39
51
|
|
40
|
-
should '
|
41
|
-
assert_raise
|
52
|
+
should 'raise an error when targets is not given' do
|
53
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_targets) }
|
42
54
|
end
|
43
55
|
|
44
|
-
should '
|
45
|
-
assert_raise
|
56
|
+
should 'raise an error when dump_dir is not given' do
|
57
|
+
assert_raise(Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_dump_dir) }
|
58
|
+
end
|
59
|
+
|
60
|
+
# ============================================================================
|
61
|
+
# INVALID FORMAT
|
62
|
+
# ============================================================================
|
63
|
+
|
64
|
+
should 'raise an error when generator given has port' do
|
65
|
+
assert_raise(Sitemaps::InvalidConfigurationError) do
|
66
|
+
Sitemaps::Configuration.new(@gen_n_port)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
should 'raise an error when generator given includes "http://" prefixed' do
|
71
|
+
assert_raise(Sitemaps::InvalidConfigurationError) do
|
72
|
+
Sitemaps::Configuration.new(@gen_n_http)
|
73
|
+
end
|
46
74
|
end
|
47
75
|
|
48
76
|
# ============================================================================
|
@@ -54,7 +82,15 @@ class ConfigurationTest < Test::Unit::TestCase
|
|
54
82
|
end
|
55
83
|
|
56
84
|
should 'retrive generator' do
|
57
|
-
assert_equal '
|
85
|
+
assert_equal 'localhost', config.generator
|
86
|
+
end
|
87
|
+
|
88
|
+
should 'retrive generator port' do
|
89
|
+
assert_equal 3000, config.generator_port
|
90
|
+
end
|
91
|
+
|
92
|
+
should 'retrive ttl' do
|
93
|
+
assert_equal 999, config.generator_timeout
|
58
94
|
end
|
59
95
|
|
60
96
|
should 'retrive domain' do
|
@@ -1,16 +1,48 @@
|
|
1
1
|
|
2
2
|
configuration:
|
3
3
|
|
4
|
-
#
|
5
|
-
|
4
|
+
# Machine that generates your sitemaps
|
5
|
+
# do not prefix "http://" nor append the port
|
6
|
+
generator: localhost
|
6
7
|
|
7
|
-
#
|
8
|
+
# The http-port of your generator
|
9
|
+
generator_port: 3000
|
10
|
+
|
11
|
+
# The time to wait for each sitemap to be received
|
12
|
+
generator_timeout: 999
|
13
|
+
|
14
|
+
# Domain from where the sitemaps will be available.
|
15
|
+
# It is important that you do not append the last slash
|
16
|
+
# otherwise you may get an error message
|
17
|
+
#
|
18
|
+
# NG
|
19
|
+
# http://example.com/
|
20
|
+
#
|
21
|
+
# OK
|
22
|
+
# http://example.com
|
23
|
+
#
|
8
24
|
domain: http://example.com
|
9
25
|
|
10
|
-
#
|
26
|
+
# Path to sitemaps to be compiled on "generator".
|
27
|
+
# For example: if you have the following url
|
28
|
+
#
|
29
|
+
# http://localhost:3000/sitemap_for/users.xml
|
30
|
+
#
|
31
|
+
# The target must be specified as such
|
32
|
+
#
|
33
|
+
# Note: you can have multiple targets
|
34
|
+
#
|
11
35
|
targets:
|
12
36
|
- /sitemap_for/users.xml
|
13
37
|
|
14
|
-
#
|
38
|
+
# Directory where compressed maps will be placed.
|
39
|
+
#
|
40
|
+
# Its a good idea to use a sub-path in your domain.
|
41
|
+
#
|
42
|
+
# For example:
|
43
|
+
# (your dump_dir could be sitemaps for the following url)
|
44
|
+
#
|
45
|
+
# http://example.com/sitemaps
|
46
|
+
#
|
15
47
|
dump_dir: sitemaps
|
16
48
|
|
data/test/generator_test.rb
CHANGED
@@ -22,7 +22,7 @@ class GeneratorTest < Test::Unit::TestCase
|
|
22
22
|
|
23
23
|
should 'get config' do
|
24
24
|
config = Sitemaps::Generator.new(@config).configuration
|
25
|
-
assert_equal config.generator, '
|
25
|
+
assert_equal config.generator, 'localhost'
|
26
26
|
end
|
27
27
|
|
28
28
|
should 'change config' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ktlacaelel-sitemaps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kazuyoshi tlacaelel
|
@@ -56,18 +56,21 @@ files:
|
|
56
56
|
- sitemaps.gemspec
|
57
57
|
- test/configuration_test.rb
|
58
58
|
- test/data/empty_configuration_file.yml
|
59
|
+
- test/data/generator_with_http_configuration_file.yml
|
60
|
+
- test/data/generator_with_port_configuration_file.yml
|
59
61
|
- test/data/invalid_configuration_file.yml
|
60
62
|
- test/data/no_domain_configuration_file.yml
|
61
63
|
- test/data/no_dump_dir_configuration_file.yml
|
62
64
|
- test/data/no_generator_configuration_file.yml
|
65
|
+
- test/data/no_port_configuration_file.yml
|
63
66
|
- test/data/no_targets_configuration_file.yml
|
67
|
+
- test/data/no_timeout_configuration_file.yml
|
64
68
|
- test/data/valid_configuration_file.yml
|
65
69
|
- test/data/valid_configuration_file2.yml
|
66
70
|
- test/generator_test.rb
|
67
71
|
- test/test_helper.rb
|
68
72
|
has_rdoc: false
|
69
73
|
homepage: http://github.com/ktlacaelel/sitemaps
|
70
|
-
licenses:
|
71
74
|
post_install_message:
|
72
75
|
rdoc_options:
|
73
76
|
- --charset=UTF-8
|
@@ -88,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
91
|
requirements: []
|
89
92
|
|
90
93
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.
|
94
|
+
rubygems_version: 1.2.0
|
92
95
|
signing_key:
|
93
96
|
specification_version: 3
|
94
97
|
summary: Setup a config yaml file. I will download & compress your sitemaps!
|