rewritten 0.4.0 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c3f8baf622f9b4ce4351475c13fc1dc0eb73d86
4
- data.tar.gz: 0afcf0f5c164bbae531c82692702305818cee956
3
+ metadata.gz: 7457fe2750b09f702f64e2255515fcb1b7d681f1
4
+ data.tar.gz: a7653f8eb5b983e220f4332d6395d0f17fec6e4a
5
5
  SHA512:
6
- metadata.gz: efb7ccf5dfa9d2b060c97960a677da421651dcc7ed6ba91f12d8373754d7bd6e4c682e8234106ea3ac4fd91af0dbab92bc950e7d44de08b8067d4afb2440d2a6
7
- data.tar.gz: 0380009037fce092fabab01e3fbf902521513fe52470f8f0158313ba4c4c118c57eb88735db61d6b35c5e3fbe7d6b46ec5fc203bbc383be3ffaf0c50e44a0202
6
+ metadata.gz: e0f1fb6a8ee92c5517963ec40e34d7ac286312ae4382049c9b10209e3402b6a858d7d9346abd06fc0925ad3124c9a7c6f5523f0ddaf9e603d3d9215c66b5020e
7
+ data.tar.gz: 23194964b145fe819f7aa68a6bc327661f932483a5046d16d9868604c350be7fc829cf2c6c82aaa0e77dc953f05e57fa0ef8d403fb96b98af7afb3b200ec9351
data/HISTORY.rdoc CHANGED
@@ -1,3 +1,12 @@
1
+ == 0.5.0
2
+
3
+ * dump and import scripts in bin/
4
+
5
+ == 0.4.0
6
+
7
+ * keep query parameters when doing 301 redirects
8
+ * test suite
9
+
1
10
  == 0.3.3
2
11
 
3
12
  * Possibly fixing new relic compatiblity: Only process successful responses in Rewritten::HTML
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'optparse'
6
+ require 'rewritten'
7
+
8
+ options = {
9
+ :out => 'rewritten.csv',
10
+ :verbose => false
11
+ }
12
+
13
+ op = OptionParser.new do |opts|
14
+ opts.banner = "Usage: rewriten-dump.rb [options]"
15
+
16
+ opts.on("-v", "--verbose", "be more verbose") do
17
+ options[:verbose] = true
18
+ end
19
+
20
+ opts.on("-o", "--out FILE", 'output file or "-" for stdout') do |o|
21
+ options[:out] = o
22
+ end
23
+
24
+ opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
25
+ options[:uri] = uri
26
+ end
27
+
28
+ opts.on("-h", "--help", 'print help') do
29
+ puts opts
30
+ exit 0
31
+ end
32
+
33
+ end
34
+ op.parse!
35
+
36
+ Rewritten.redis = options[:uri] if options[:uri]
37
+
38
+ file = options[:out] == "-" ? STDOUT : File.open(options[:out], "w")
39
+
40
+ file.puts "#from;to"
41
+ Rewritten.all_tos.each do |to|
42
+ file.puts Rewritten.get_all_translations(to).map{|from| "#{from};#{to}"}.join("\n")
43
+ end
44
+
45
+
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'optparse'
6
+ require 'rewritten'
7
+ require 'multi_json'
8
+
9
+ options = {
10
+ :drop => false
11
+ }
12
+
13
+ op = OptionParser.new do |opts|
14
+ opts.banner = "Usage: rewriten-dump.rb [options]"
15
+
16
+ opts.on("-v", "--verbose", "be more verbose") do |v|
17
+ options[:verbose] = v
18
+ end
19
+
20
+ opts.on("-f", "--file FILE", 'input file') do |o|
21
+ options[:file] = o
22
+ end
23
+
24
+ opts.on("-u", "--uri URI", 'uri to the redis db') do |uri|
25
+ options[:uri] = uri
26
+ end
27
+
28
+ opts.on("-d", "--drop", 'drop translations first') do
29
+ options[:drop] = true
30
+ end
31
+
32
+ end
33
+
34
+ op.parse!
35
+
36
+ unless options[:file]
37
+ puts op
38
+ exit
39
+ end
40
+
41
+ Rewritten.redis = options[:uri] if options[:uri]
42
+
43
+ Rewritten.clear_translations if options[:drop]
44
+
45
+ File.open(options[:file]).each do |line|
46
+ next if line =~ /^#/
47
+ from,to = line.split(";")
48
+ puts "adding #{from} -> #{to}" if options[:verbose]
49
+ Rewritten.add_translation(from,to)
50
+ end
51
+
52
+
@@ -1,4 +1,4 @@
1
1
  module Rewritten
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
4
4
 
data/lib/rewritten.rb CHANGED
@@ -6,6 +6,7 @@ require 'rack/url'
6
6
  require 'rack/record'
7
7
  require 'rack/html'
8
8
  require 'rack/subdomain'
9
+ require 'pry'
9
10
 
10
11
  module Rewritten
11
12
  include Helpers
@@ -160,8 +161,33 @@ module Rewritten
160
161
  end
161
162
  end
162
163
 
164
+ def clear_translations
165
+ if Rewritten.redis == :test
166
+ @static_translations = {}
167
+ else
168
+ Rewritten.redis.del(*Rewritten.redis.keys) unless Rewritten.redis.keys.empty?
169
+ end
170
+ end
171
+
172
+ def all_tos
173
+ tos = []
174
+ if Rewritten.redis == :test
175
+ tos = @static_translations.values.uniq
176
+ else
177
+ tos = Rewritten.redis.lrange("tos",0,-1).uniq
178
+ end
179
+ end
180
+
181
+ def all_translations
182
+ Hash[all_tos.map {|to| [to, Rewritten.get_all_translations(to)]}]
183
+ end
184
+
163
185
  def get_all_translations(to)
164
- Rewritten.redis.lrange("to:#{to}", 0, -1)
186
+ if Rewritten.redis == :test
187
+ @static_translations.to_a.select{|k,v| v == to}.map{|k,v| k}
188
+ else
189
+ Rewritten.redis.lrange("to:#{to}", 0, -1)
190
+ end
165
191
  end
166
192
 
167
193
  def get_current_translation(path)
@@ -0,0 +1,25 @@
1
+ require 'rewritten'
2
+ require 'minitest/autorun'
3
+
4
+ describe Rewritten do
5
+
6
+ before{
7
+ Rewritten.redis = :test
8
+ Rewritten.clear_translations
9
+ Rewritten.add_translation('/from', '/to')
10
+ Rewritten.add_translation('/from2', '/to')
11
+ Rewritten.add_translation('/from3', '/to2')
12
+ }
13
+
14
+ it "must give all tos" do
15
+ Rewritten.all_tos.must_equal ["/to", "/to2"]
16
+ end
17
+
18
+ it "must return all translations" do
19
+ expected = { "/to" => ['/from', '/from2'], "/to2" => ['/from3']}
20
+ Rewritten.all_translations.must_equal expected
21
+ end
22
+
23
+ end
24
+
25
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rewritten
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kai Rubarth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-03 00:00:00.000000000 Z
11
+ date: 2013-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-namespace
@@ -128,6 +128,8 @@ description: |2
128
128
  email:
129
129
  - kai@doxter.de
130
130
  executables:
131
+ - rewritten-dump.rb
132
+ - rewritten-import.rb
131
133
  - rewritten-web.rb
132
134
  extensions: []
133
135
  extra_rdoc_files: []
@@ -137,6 +139,8 @@ files:
137
139
  - HISTORY.rdoc
138
140
  - README.rdoc
139
141
  - Rakefile
142
+ - bin/rewritten-dump.rb
143
+ - bin/rewritten-import.rb
140
144
  - bin/rewritten-web.rb
141
145
  - config.ru
142
146
  - lib/rack/dummy.rb
@@ -176,8 +180,8 @@ files:
176
180
  - lib/rewritten/version.rb
177
181
  - lib/test.ru
178
182
  - rewritten.gemspec
179
- - test/rewritten_url_test.rb
180
- - test/test_rewritten.rb
183
+ - test/rack/rewritten_url_test.rb
184
+ - test/rewritten_test.rb
181
185
  homepage: ''
182
186
  licenses: []
183
187
  metadata: {}
@@ -1,6 +0,0 @@
1
- require 'rubygems'
2
- require 'rack'
3
- require "../lib/rack/dummy"
4
-
5
- run Rack::Dummy.new
6
-