ktlacaelel-sitemaps 0.2.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,4 +3,3 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
- sitemaps
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.4.2
data/bin/sitemaps ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'sitemaps'
5
+
6
+ configuration = Sitemaps::Configuration.new(ARGV[0])
7
+ Sitemaps::Generator.new(configuration).execute!
8
+
data/lib/generator.rb CHANGED
@@ -1,6 +1,83 @@
1
1
  module Sitemaps
2
2
 
3
3
  class Generator
4
+
5
+ attr_reader :configuration
6
+
7
+ def initialize(configuration_object)
8
+ self.configuration = configuration_object
9
+ end
10
+
11
+ def prepare
12
+ Dir.mkdir configuration.dump_dir
13
+ end
14
+
15
+ def configuration=(object)
16
+ unless object.is_a? Configuration
17
+ raise InvalidConfigurationError.new('Not a sitemap configuration object!')
18
+ end
19
+ @configuration = object
20
+ end
21
+
22
+ def execute!
23
+ download!
24
+ compress!
25
+ end
26
+
27
+ protected
28
+
29
+ def download!
30
+ ensure_dump_dir
31
+ Net::HTTP.start(@configuration.generator, '3000') do |http|
32
+ @configuration.targets.each do |target|
33
+ store_downloaded_data target, http.get(target).body
34
+ end
35
+ end
36
+ end
37
+
38
+ def compress!
39
+ ensure_compress_dir
40
+ Dir.glob(download_path + '/*').each do |file|
41
+ Zlib::GzipWriter.open(get_gzip_filename(file)) do |gz|
42
+ gz.write File.read(file)
43
+ end
44
+ end
45
+ end
46
+
47
+ def get_gzip_filename(long_path)
48
+ File.join(compress_path, File.basename(long_path) + '.gz')
49
+ end
50
+
51
+ def ensure_dump_dir
52
+ [@configuration.dump_dir, download_path].each do |path|
53
+ Dir.mkdir path unless File.exist? path
54
+ end
55
+ end
56
+
57
+ def ensure_compress_dir
58
+ unless File.exist? compress_path
59
+ Dir.mkdir compress_path
60
+ end
61
+ end
62
+
63
+ def store_downloaded_data(target, data)
64
+ File.open(download_target_for(target), 'w+') do |file|
65
+ file.write data
66
+ end
67
+ end
68
+
69
+ def compress_path
70
+ @compress_path ||= File.join(@configuration.dump_dir, @configuration.dump_dir)
71
+ end
72
+
73
+ def download_target_for(target)
74
+ File.join(download_path, File.basename(target))
75
+ end
76
+
77
+ def download_path
78
+ File.join(@configuration.dump_dir, 'downloads')
79
+ end
80
+
4
81
  end
5
82
 
6
83
  end
@@ -1,2 +1,6 @@
1
- class InvalidConfigurationError < Exception
1
+ module Sitemaps
2
+
3
+ class InvalidConfigurationError < Exception
4
+ end
5
+
2
6
  end
data/lib/sitemaps.rb CHANGED
@@ -5,7 +5,6 @@ require 'yaml'
5
5
  require 'zlib'
6
6
 
7
7
  # internal libraries
8
- require 'cli'
9
8
  require 'configuration'
10
9
  require 'invalid_configuration_error'
11
10
  require 'generator'
data/sitemaps.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sitemaps}
8
- s.version = "0.2.0"
8
+ s.version = "0.4.2"
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"]
12
- s.date = %q{2009-09-10}
12
+ s.date = %q{2009-09-15}
13
+ s.default_executable = %q{sitemaps}
13
14
  s.description = %q{Setup a config file & execute. I will download and compress your sitemaps!}
14
15
  s.email = %q{kazu.dev@gmail.com}
16
+ s.executables = ["sitemaps"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
@@ -23,13 +25,12 @@ Gem::Specification.new do |s|
23
25
  "README.rdoc",
24
26
  "Rakefile",
25
27
  "VERSION",
26
- "lib/cli.rb",
28
+ "bin/sitemaps",
27
29
  "lib/configuration.rb",
28
30
  "lib/generator.rb",
29
31
  "lib/invalid_configuration_error.rb",
30
32
  "lib/sitemaps.rb",
31
33
  "sitemaps.gemspec",
32
- "test/cli_test.rb",
33
34
  "test/configuration_test.rb",
34
35
  "test/data/empty_configuration_file.yml",
35
36
  "test/data/invalid_configuration_file.yml",
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
38
39
  "test/data/no_generator_configuration_file.yml",
39
40
  "test/data/no_targets_configuration_file.yml",
40
41
  "test/data/valid_configuration_file.yml",
42
+ "test/data/valid_configuration_file2.yml",
41
43
  "test/generator_test.rb",
42
44
  "test/test_helper.rb"
43
45
  ]
@@ -47,8 +49,7 @@ Gem::Specification.new do |s|
47
49
  s.rubygems_version = %q{1.3.3}
48
50
  s.summary = %q{SEO Sitemap Generator}
49
51
  s.test_files = [
50
- "test/cli_test.rb",
51
- "test/configuration_test.rb",
52
+ "test/configuration_test.rb",
52
53
  "test/generator_test.rb",
53
54
  "test/test_helper.rb"
54
55
  ]
@@ -17,8 +17,8 @@ class ConfigurationTest < Test::Unit::TestCase
17
17
  # ============================================================================
18
18
 
19
19
  should 'check if configuration file exists' do
20
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new('a') }
21
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(nil) }
20
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new('a') }
21
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(nil) }
22
22
  end
23
23
 
24
24
  should 'load a configuration file' do
@@ -30,19 +30,19 @@ class ConfigurationTest < Test::Unit::TestCase
30
30
  # ============================================================================
31
31
 
32
32
  should 'throw an error when generator is not given' do
33
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_generator) }
33
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_generator) }
34
34
  end
35
35
 
36
36
  should 'throw an error when domain is not given' do
37
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_domain) }
37
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_domain) }
38
38
  end
39
39
 
40
40
  should 'throw an error when targets is not given' do
41
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_targets) }
41
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_targets) }
42
42
  end
43
43
 
44
44
  should 'throw an error when dump_dir is not given' do
45
- assert_raise (InvalidConfigurationError) { Sitemaps::Configuration.new(@no_dump_dir) }
45
+ assert_raise (Sitemaps::InvalidConfigurationError) { Sitemaps::Configuration.new(@no_dump_dir) }
46
46
  end
47
47
 
48
48
  # ============================================================================
@@ -0,0 +1,16 @@
1
+
2
+ configuration:
3
+
4
+ # machine that generates sitemaps in xml format
5
+ generator: http://xxxxxxxxx
6
+
7
+ # domain from where the sitemaps will be available
8
+ domain: http://example.com
9
+
10
+ # path to sitemaps to be compiled
11
+ targets:
12
+ - /sitemap_for/users.xml
13
+
14
+ # directory where compressed maps will be placed
15
+ dump_dir: sitemaps
16
+
@@ -4,16 +4,18 @@ class GeneratorTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
6
  @valid = 'test/data/valid_configuration_file.yml'
7
+ @valid2 = 'test/data/valid_configuration_file2.yml'
7
8
  @config = Sitemaps::Configuration.new(@valid)
8
9
  end
9
10
 
10
11
  should 'check for a sitemap configuration on instantiantion' do
11
- assert_raise (InvalidConfigurationError) do
12
+ assert_raise (Sitemaps::InvalidConfigurationError) do
12
13
  Sitemaps::Generator.new(nil)
13
14
  end
14
15
  end
15
16
 
16
17
  should 'prepare dump_dir' do
18
+ `rm -rf sitemaps`
17
19
  Sitemaps::Generator.new(@config).prepare
18
20
  assert File.exist? 'sitemaps'
19
21
  end
@@ -25,9 +27,9 @@ class GeneratorTest < Test::Unit::TestCase
25
27
 
26
28
  should 'change config' do
27
29
  generator = Sitemaps::Generator.new(@config)
28
- @config.stub(:generator).returns('changed!')
29
- generator.change_config @config
30
- assert_equal generator.configuration.generator, 'changed!'
30
+ new_config = Sitemaps::Configuration.new(@valid2)
31
+ generator.configuration = new_config
32
+ assert_equal new_config, generator.configuration
31
33
  end
32
34
 
33
35
  should 'should download sitemaps'
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.2.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kazuyoshi tlacaelel
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-10 00:00:00 -07:00
13
- default_executable:
12
+ date: 2009-09-15 00:00:00 -07:00
13
+ default_executable: sitemaps
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thoughtbot-shoulda
@@ -24,8 +24,8 @@ dependencies:
24
24
  version:
25
25
  description: Setup a config file & execute. I will download and compress your sitemaps!
26
26
  email: kazu.dev@gmail.com
27
- executables: []
28
-
27
+ executables:
28
+ - sitemaps
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
@@ -38,13 +38,12 @@ files:
38
38
  - README.rdoc
39
39
  - Rakefile
40
40
  - VERSION
41
- - lib/cli.rb
41
+ - bin/sitemaps
42
42
  - lib/configuration.rb
43
43
  - lib/generator.rb
44
44
  - lib/invalid_configuration_error.rb
45
45
  - lib/sitemaps.rb
46
46
  - sitemaps.gemspec
47
- - test/cli_test.rb
48
47
  - test/configuration_test.rb
49
48
  - test/data/empty_configuration_file.yml
50
49
  - test/data/invalid_configuration_file.yml
@@ -53,6 +52,7 @@ files:
53
52
  - test/data/no_generator_configuration_file.yml
54
53
  - test/data/no_targets_configuration_file.yml
55
54
  - test/data/valid_configuration_file.yml
55
+ - test/data/valid_configuration_file2.yml
56
56
  - test/generator_test.rb
57
57
  - test/test_helper.rb
58
58
  has_rdoc: false
@@ -82,7 +82,6 @@ signing_key:
82
82
  specification_version: 3
83
83
  summary: SEO Sitemap Generator
84
84
  test_files:
85
- - test/cli_test.rb
86
85
  - test/configuration_test.rb
87
86
  - test/generator_test.rb
88
87
  - test/test_helper.rb
data/lib/cli.rb DELETED
@@ -1,6 +0,0 @@
1
- module Sitemaps
2
-
3
- class Cli
4
- end
5
-
6
- end
data/test/cli_test.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CliTest < Test::Unit::TestCase
4
- end