rivendell-import 0.0.4 → 0.0.5
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/Gemfile +4 -5
- data/Gemfile.lock +79 -34
- data/examples/config.rb +1 -2
- data/lib/rivendell/import/base.rb +4 -1
- data/lib/rivendell/import/cart.rb +15 -4
- data/lib/rivendell/import/cart_finder.rb +62 -0
- data/lib/rivendell/import/cart_finder_by_db.rb +18 -0
- data/lib/rivendell/import/cli.rb +4 -4
- data/lib/rivendell/import/config_loader.rb +2 -2
- data/lib/rivendell/import/task.rb +10 -0
- data/lib/rivendell/import/version.rb +1 -1
- data/lib/rivendell/import.rb +5 -1
- data/rivendell-import.gemspec +3 -1
- data/spec/rivendell/import/{carts_cache_spec.rb → cart_finder_spec.rb} +63 -25
- data/spec/rivendell/import/task_spec.rb +21 -0
- metadata +28 -11
- data/lib/rivendell/import/carts_cache.rb +0 -58
data/Gemfile
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
source "
|
|
1
|
+
source "https://rubygems.org"
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# gem "rivendell-db", :path => "~/Projects/RivendellDb"
|
|
6
6
|
|
|
7
7
|
if RUBY_PLATFORM =~ /linux/
|
|
8
|
-
gem 'libnotify'
|
|
9
|
-
gem 'rb-inotify'
|
|
8
|
+
gem 'libnotify'
|
|
9
|
+
gem 'rb-inotify'
|
|
10
10
|
end
|
|
11
|
-
|
data/Gemfile.lock
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rivendell-import (0.0.
|
|
4
|
+
rivendell-import (0.0.5)
|
|
5
5
|
SyslogLogger (~> 2.0)
|
|
6
6
|
activerecord (~> 3.2.8)
|
|
7
7
|
activesupport (~> 3.2.8)
|
|
8
8
|
daemons
|
|
9
9
|
httmultiparty
|
|
10
|
-
listen
|
|
10
|
+
listen (~> 1.2.1)
|
|
11
11
|
mail
|
|
12
12
|
rivendell-api (~> 0.0.4)
|
|
13
|
+
rivendell-db
|
|
13
14
|
sinatra
|
|
14
15
|
sqlite3
|
|
15
16
|
trollop
|
|
16
17
|
will_paginate (~> 3.0.0)
|
|
17
18
|
|
|
18
19
|
GEM
|
|
19
|
-
remote:
|
|
20
|
+
remote: https://rubygems.org/
|
|
20
21
|
specs:
|
|
21
22
|
SyslogLogger (2.0)
|
|
22
|
-
activemodel (3.2.
|
|
23
|
-
activesupport (= 3.2.
|
|
23
|
+
activemodel (3.2.13)
|
|
24
|
+
activesupport (= 3.2.13)
|
|
24
25
|
builder (~> 3.0.0)
|
|
25
|
-
activerecord (3.2.
|
|
26
|
-
activemodel (= 3.2.
|
|
27
|
-
activesupport (= 3.2.
|
|
26
|
+
activerecord (3.2.13)
|
|
27
|
+
activemodel (= 3.2.13)
|
|
28
|
+
activesupport (= 3.2.13)
|
|
28
29
|
arel (~> 3.0.2)
|
|
29
30
|
tzinfo (~> 0.3.29)
|
|
30
|
-
activesupport (3.2.
|
|
31
|
-
i18n (
|
|
31
|
+
activesupport (3.2.13)
|
|
32
|
+
i18n (= 0.6.1)
|
|
32
33
|
multi_json (~> 1.0)
|
|
34
|
+
addressable (2.3.5)
|
|
33
35
|
arel (3.0.2)
|
|
36
|
+
bcrypt-ruby (3.0.1)
|
|
34
37
|
builder (3.0.3)
|
|
35
38
|
cucumber (1.2.1)
|
|
36
39
|
builder (>= 2.1.2)
|
|
@@ -38,9 +41,38 @@ GEM
|
|
|
38
41
|
gherkin (~> 2.11.0)
|
|
39
42
|
json (>= 1.4.6)
|
|
40
43
|
daemons (1.1.9)
|
|
44
|
+
data_objects (0.10.13)
|
|
45
|
+
addressable (~> 2.1)
|
|
41
46
|
database_cleaner (0.8.0)
|
|
42
47
|
diff-lcs (1.1.3)
|
|
43
|
-
|
|
48
|
+
dm-core (1.2.1)
|
|
49
|
+
addressable (~> 2.3)
|
|
50
|
+
dm-do-adapter (1.2.0)
|
|
51
|
+
data_objects (~> 0.10.6)
|
|
52
|
+
dm-core (~> 1.2.0)
|
|
53
|
+
dm-mysql-adapter (1.2.0)
|
|
54
|
+
dm-do-adapter (~> 1.2.0)
|
|
55
|
+
do_mysql (~> 0.10.6)
|
|
56
|
+
dm-serializer (1.2.2)
|
|
57
|
+
dm-core (~> 1.2.0)
|
|
58
|
+
fastercsv (~> 1.5)
|
|
59
|
+
json (~> 1.6)
|
|
60
|
+
json_pure (~> 1.6)
|
|
61
|
+
multi_json (~> 1.0)
|
|
62
|
+
dm-types (1.2.2)
|
|
63
|
+
bcrypt-ruby (~> 3.0)
|
|
64
|
+
dm-core (~> 1.2.0)
|
|
65
|
+
fastercsv (~> 1.5)
|
|
66
|
+
json (~> 1.6)
|
|
67
|
+
multi_json (~> 1.0)
|
|
68
|
+
stringex (~> 1.4)
|
|
69
|
+
uuidtools (~> 2.1)
|
|
70
|
+
dm-validations (1.2.0)
|
|
71
|
+
dm-core (~> 1.2.0)
|
|
72
|
+
do_mysql (0.10.13)
|
|
73
|
+
data_objects (= 0.10.13)
|
|
74
|
+
fastercsv (1.5.5)
|
|
75
|
+
ffi (1.9.0)
|
|
44
76
|
gherkin (2.11.2)
|
|
45
77
|
json (>= 1.4.6)
|
|
46
78
|
guard (1.4.0)
|
|
@@ -52,37 +84,49 @@ GEM
|
|
|
52
84
|
guard-rspec (2.0.0)
|
|
53
85
|
guard (>= 1.1)
|
|
54
86
|
rspec (~> 2.11)
|
|
55
|
-
httmultiparty (0.3.
|
|
87
|
+
httmultiparty (0.3.10)
|
|
56
88
|
httparty (>= 0.7.3)
|
|
57
89
|
multipart-post
|
|
58
|
-
httparty (0.
|
|
90
|
+
httparty (0.11.0)
|
|
59
91
|
multi_json (~> 1.0)
|
|
60
|
-
multi_xml
|
|
92
|
+
multi_xml (>= 0.5.2)
|
|
61
93
|
i18n (0.6.1)
|
|
62
94
|
json (1.7.5)
|
|
95
|
+
json_pure (1.8.0)
|
|
63
96
|
libnotify (0.8.0)
|
|
64
97
|
ffi (>= 1.0.11)
|
|
65
|
-
listen (
|
|
66
|
-
|
|
67
|
-
|
|
98
|
+
listen (1.2.2)
|
|
99
|
+
rb-fsevent (>= 0.9.3)
|
|
100
|
+
rb-inotify (>= 0.9)
|
|
101
|
+
rb-kqueue (>= 0.2)
|
|
102
|
+
mail (2.5.4)
|
|
68
103
|
mime-types (~> 1.16)
|
|
69
104
|
treetop (~> 1.4.8)
|
|
70
|
-
mime-types (1.
|
|
105
|
+
mime-types (1.23)
|
|
71
106
|
multi_json (1.4.0)
|
|
72
|
-
multi_xml (0.5.
|
|
73
|
-
multipart-post (1.
|
|
107
|
+
multi_xml (0.5.4)
|
|
108
|
+
multipart-post (1.2.0)
|
|
74
109
|
null_logger (0.0.1)
|
|
75
110
|
polyglot (0.3.3)
|
|
76
|
-
rack (1.
|
|
77
|
-
rack-protection (1.
|
|
111
|
+
rack (1.5.2)
|
|
112
|
+
rack-protection (1.5.0)
|
|
78
113
|
rack
|
|
79
114
|
rake (0.9.2.2)
|
|
80
|
-
rb-
|
|
115
|
+
rb-fsevent (0.9.3)
|
|
116
|
+
rb-inotify (0.9.0)
|
|
117
|
+
ffi (>= 0.5.0)
|
|
118
|
+
rb-kqueue (0.2.0)
|
|
81
119
|
ffi (>= 0.5.0)
|
|
82
120
|
rivendell-api (0.0.4)
|
|
83
121
|
activesupport
|
|
84
122
|
httmultiparty
|
|
85
123
|
null_logger
|
|
124
|
+
rivendell-db (0.0.1)
|
|
125
|
+
dm-core
|
|
126
|
+
dm-mysql-adapter
|
|
127
|
+
dm-serializer
|
|
128
|
+
dm-types
|
|
129
|
+
dm-validations
|
|
86
130
|
rspec (2.11.0)
|
|
87
131
|
rspec-core (~> 2.11.0)
|
|
88
132
|
rspec-expectations (~> 2.11.0)
|
|
@@ -95,19 +139,21 @@ GEM
|
|
|
95
139
|
multi_json (~> 1.0)
|
|
96
140
|
simplecov-html (~> 0.5.3)
|
|
97
141
|
simplecov-html (0.5.3)
|
|
98
|
-
sinatra (1.
|
|
99
|
-
rack (~> 1.
|
|
100
|
-
rack-protection (~> 1.
|
|
101
|
-
tilt (~> 1.3, >= 1.3.
|
|
102
|
-
sqlite3 (1.3.
|
|
142
|
+
sinatra (1.4.3)
|
|
143
|
+
rack (~> 1.4)
|
|
144
|
+
rack-protection (~> 1.4)
|
|
145
|
+
tilt (~> 1.3, >= 1.3.4)
|
|
146
|
+
sqlite3 (1.3.7)
|
|
147
|
+
stringex (1.5.1)
|
|
103
148
|
thor (0.16.0)
|
|
104
|
-
tilt (1.
|
|
105
|
-
treetop (1.4.
|
|
149
|
+
tilt (1.4.1)
|
|
150
|
+
treetop (1.4.14)
|
|
106
151
|
polyglot
|
|
107
152
|
polyglot (>= 0.3.1)
|
|
108
153
|
trollop (2.0)
|
|
109
|
-
tzinfo (0.3.
|
|
110
|
-
|
|
154
|
+
tzinfo (0.3.37)
|
|
155
|
+
uuidtools (2.1.4)
|
|
156
|
+
will_paginate (3.0.4)
|
|
111
157
|
|
|
112
158
|
PLATFORMS
|
|
113
159
|
ruby
|
|
@@ -120,8 +166,7 @@ DEPENDENCIES
|
|
|
120
166
|
guard-rspec
|
|
121
167
|
libnotify
|
|
122
168
|
rake
|
|
123
|
-
rb-inotify
|
|
124
|
-
rivendell-api
|
|
169
|
+
rb-inotify
|
|
125
170
|
rivendell-import!
|
|
126
171
|
rspec
|
|
127
172
|
simplecov
|
data/examples/config.rb
CHANGED
|
@@ -15,7 +15,6 @@ end
|
|
|
15
15
|
Rivendell::Import::Notifier::Mail.from = "root@tryphon.eu"
|
|
16
16
|
|
|
17
17
|
Rivendell::Import.config do |config|
|
|
18
|
-
|
|
19
18
|
config.rivendell.host = "localhost"
|
|
20
19
|
config.rivendell.login_name = "user"
|
|
21
20
|
config.rivendell.password = ""
|
|
@@ -29,7 +28,7 @@ Rivendell::Import.config do |config|
|
|
|
29
28
|
cart.clear_cuts!
|
|
30
29
|
cart.find_by_title file.basename
|
|
31
30
|
end
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
cart.group ||= "TEST"
|
|
34
33
|
|
|
35
34
|
# To delete file when task is completed
|
|
@@ -22,12 +22,15 @@ module Rivendell::Import
|
|
|
22
22
|
workers << Worker.new(self).start unless options[:dry_run]
|
|
23
23
|
|
|
24
24
|
Rivendell::Import.logger.info "Listen files in #{directory}"
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
callback = Proc.new do |modified, added, removed|
|
|
26
27
|
added.each do |file|
|
|
27
28
|
Rivendell::Import.logger.debug "Detected file '#{file}'"
|
|
28
29
|
file(file, directory)
|
|
29
30
|
end
|
|
30
31
|
end
|
|
32
|
+
|
|
33
|
+
Listen.to(directory).change(&callback).start!
|
|
31
34
|
end
|
|
32
35
|
|
|
33
36
|
def process(*paths)
|
|
@@ -54,7 +54,7 @@ module Rivendell::Import
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def find_by_title(string, options = {})
|
|
57
|
-
if remote_cart =
|
|
57
|
+
if remote_cart = cart_finder.find_by_title(string, options)
|
|
58
58
|
self.number = remote_cart.number
|
|
59
59
|
end
|
|
60
60
|
end
|
|
@@ -66,10 +66,21 @@ module Rivendell::Import
|
|
|
66
66
|
self.clear_cuts = true
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
@db_url = nil
|
|
70
|
+
cattr_accessor :db_url
|
|
71
|
+
|
|
72
|
+
def cart_finder
|
|
73
|
+
@cart_finder ||=
|
|
74
|
+
begin
|
|
75
|
+
unless db_url
|
|
76
|
+
Rivendell::Import::CartFinder::ByApi.new xport
|
|
77
|
+
else
|
|
78
|
+
Rivendell::DB.establish_connection(db_url)
|
|
79
|
+
Rivendell::Import::CartFinder::ByDb.new
|
|
80
|
+
end
|
|
81
|
+
end
|
|
71
82
|
end
|
|
72
|
-
|
|
83
|
+
|
|
73
84
|
end
|
|
74
85
|
end
|
|
75
86
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Rivendell::Import
|
|
2
|
+
class CartFinder
|
|
3
|
+
|
|
4
|
+
def find_all_by_title(string, options = {})
|
|
5
|
+
normalizer = options.delete(:normalizer) || Proc.new { |id| id }
|
|
6
|
+
|
|
7
|
+
string = normalizer.call(string)
|
|
8
|
+
carts(options).select do |cart|
|
|
9
|
+
normalizer.call(cart.title) == string
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def default_normalizer
|
|
14
|
+
Proc.new do |string|
|
|
15
|
+
ActiveSupport::Multibyte::Chars.new(string).normalize(:kd).gsub(/[^\x00-\x7F]/n,'').downcase.to_s.gsub(/[^a-z0-9]/," ").gsub(/[ ]+/," ")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def find_by_title(string, options = {})
|
|
20
|
+
matching_carts = find_all_by_title(string, options)
|
|
21
|
+
|
|
22
|
+
if matching_carts.blank?
|
|
23
|
+
matching_carts = find_all_by_title(string, options.merge(:normalizer => default_normalizer))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
matching_carts.first if matching_carts.one?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class ByApi < CartFinder
|
|
30
|
+
|
|
31
|
+
attr_accessor :xport
|
|
32
|
+
|
|
33
|
+
def initialize(xport)
|
|
34
|
+
@xport = xport
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def cache
|
|
38
|
+
clear if purged_at < time_to_live.ago
|
|
39
|
+
@cache ||= {}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def clear
|
|
43
|
+
@cache = nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
@@time_to_live = 600
|
|
47
|
+
cattr_accessor :time_to_live
|
|
48
|
+
|
|
49
|
+
attr_accessor :purged_at
|
|
50
|
+
|
|
51
|
+
def purged_at
|
|
52
|
+
@purged_at ||= Time.now
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def carts(options = {})
|
|
56
|
+
cache[options.to_s] ||= xport.list_carts(options)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Find Carts using a direct database access.
|
|
2
|
+
#
|
|
3
|
+
# Provided to workaround actual accent problems experienced with Rivendell API.
|
|
4
|
+
module Rivendell::Import
|
|
5
|
+
class CartFinder::ByDb < CartFinder
|
|
6
|
+
|
|
7
|
+
def carts(options = {})
|
|
8
|
+
query_options = { :fields => [ :number, :title ] }
|
|
9
|
+
|
|
10
|
+
if options[:group]
|
|
11
|
+
query_options[:group_name] = options[:group]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
Rivendell::DB::Cart.all(query_options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/rivendell/import/cli.rb
CHANGED
|
@@ -46,7 +46,7 @@ module Rivendell::Import
|
|
|
46
46
|
|
|
47
47
|
def parser
|
|
48
48
|
@parser ||= Trollop::Parser.new do
|
|
49
|
-
opt :config, "Configuration file", :type => String
|
|
49
|
+
opt :config, "Configuration file", :type => String, :required => true
|
|
50
50
|
opt :listen, "Wait for files in given directory"
|
|
51
51
|
opt :dry_run, "Just create tasks without executing them"
|
|
52
52
|
opt :debug, "Enable debug messages (in stderr)"
|
|
@@ -78,7 +78,7 @@ module Rivendell::Import
|
|
|
78
78
|
parsed_parser.leftovers
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
def setup_logger
|
|
81
|
+
def setup_logger
|
|
82
82
|
new_logger =
|
|
83
83
|
if syslog?
|
|
84
84
|
Syslog::Logger.new('rivendell-import').tap do |syslog|
|
|
@@ -115,7 +115,7 @@ module Rivendell::Import
|
|
|
115
115
|
Daemons.daemonize :app_name => "rivendell-import", :dir => pid_directory, :dir_mode => :normal
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
def run
|
|
120
120
|
setup_logger
|
|
121
121
|
|
|
@@ -131,7 +131,7 @@ module Rivendell::Import
|
|
|
131
131
|
config_loader.listen_file
|
|
132
132
|
|
|
133
133
|
if listen_mode?
|
|
134
|
-
start_webserver
|
|
134
|
+
start_webserver
|
|
135
135
|
|
|
136
136
|
listen_options = {}
|
|
137
137
|
listen_options[:dry_run] = true if dry_run?
|
|
@@ -19,12 +19,12 @@ module Rivendell::Import
|
|
|
19
19
|
callback = Proc.new do |modified, added, removed|
|
|
20
20
|
if modified.include? absolute_path
|
|
21
21
|
Rivendell::Import.logger.info "Configuration changed, reload it"
|
|
22
|
-
load
|
|
22
|
+
load
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
Rivendell::Import.logger.info "Listen to config file changes (#{file})"
|
|
27
|
-
Listen.to(directory).filter(/^#{basename}$/).change(&callback).start
|
|
27
|
+
Listen.to(directory).filter(/^#{basename}$/).change(&callback).start
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def listen_file_with_inotify
|
data/lib/rivendell/import.rb
CHANGED
|
@@ -40,7 +40,7 @@ require "rivendell/import/worker"
|
|
|
40
40
|
require "rivendell/import/task"
|
|
41
41
|
require "rivendell/import/tasks"
|
|
42
42
|
require "rivendell/import/base"
|
|
43
|
-
require "rivendell/import/
|
|
43
|
+
require "rivendell/import/cart_finder"
|
|
44
44
|
require "rivendell/import/cart"
|
|
45
45
|
require "rivendell/import/context"
|
|
46
46
|
require "rivendell/import/cut"
|
|
@@ -48,3 +48,7 @@ require "rivendell/import/file"
|
|
|
48
48
|
require "rivendell/import/notification"
|
|
49
49
|
require "rivendell/import/notifier/base"
|
|
50
50
|
require "rivendell/import/notifier/mail"
|
|
51
|
+
|
|
52
|
+
# TODO Rivendell::Import::CartFinder::ByDb should be optional
|
|
53
|
+
require 'rivendell/db'
|
|
54
|
+
require 'rivendell/import/cart_finder_by_db'
|
data/rivendell-import.gemspec
CHANGED
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
|
15
15
|
gem.require_paths = ["lib"]
|
|
16
16
|
gem.version = Rivendell::Import::VERSION
|
|
17
17
|
|
|
18
|
-
gem.add_runtime_dependency 'listen'
|
|
18
|
+
gem.add_runtime_dependency 'listen', '~> 1.2.1'
|
|
19
19
|
gem.add_runtime_dependency 'httmultiparty'
|
|
20
20
|
gem.add_runtime_dependency 'rivendell-api', '~> 0.0.4'
|
|
21
21
|
gem.add_runtime_dependency 'trollop'
|
|
@@ -30,6 +30,8 @@ Gem::Specification.new do |gem|
|
|
|
30
30
|
|
|
31
31
|
gem.add_runtime_dependency 'daemons'
|
|
32
32
|
|
|
33
|
+
gem.add_runtime_dependency 'rivendell-db'
|
|
34
|
+
|
|
33
35
|
gem.add_development_dependency "simplecov"
|
|
34
36
|
gem.add_development_dependency "rspec"
|
|
35
37
|
gem.add_development_dependency "guard"
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
1
2
|
require 'spec_helper'
|
|
2
3
|
|
|
3
|
-
describe Rivendell::Import::
|
|
4
|
-
|
|
5
|
-
let(:carts_cache) { Rivendell::Import::CartsCache.new(xport) }
|
|
6
|
-
subject { carts_cache }
|
|
4
|
+
describe Rivendell::Import::CartFinder do
|
|
7
5
|
|
|
8
6
|
let(:cart) { mock :title => "dummy" }
|
|
9
7
|
let(:carts) { [ cart ] }
|
|
10
8
|
|
|
11
|
-
let(:
|
|
12
|
-
|
|
13
|
-
before do
|
|
14
|
-
subject.stub :xport => xport
|
|
15
|
-
end
|
|
9
|
+
let(:cart_finder) { Rivendell::Import::CartFinder.new }
|
|
10
|
+
subject { cart_finder }
|
|
16
11
|
|
|
17
12
|
describe "#find_all_by_title" do
|
|
18
13
|
|
|
@@ -41,7 +36,7 @@ describe Rivendell::Import::CartsCache do
|
|
|
41
36
|
|
|
42
37
|
describe "#default_normalizer" do
|
|
43
38
|
|
|
44
|
-
subject {
|
|
39
|
+
subject { cart_finder.default_normalizer }
|
|
45
40
|
|
|
46
41
|
it "should downcase string" do
|
|
47
42
|
subject.call("ABC").should == "abc"
|
|
@@ -54,9 +49,50 @@ describe Rivendell::Import::CartsCache do
|
|
|
54
49
|
it "should remove double spaces" do
|
|
55
50
|
subject.call("a b c").should == "a b c"
|
|
56
51
|
end
|
|
52
|
+
|
|
53
|
+
it "should remove accents" do
|
|
54
|
+
subject.call("Ç'est évident").should == "c est evident"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#find_by_title" do
|
|
60
|
+
|
|
61
|
+
before do
|
|
62
|
+
subject.stub(:carts).and_return(carts)
|
|
63
|
+
end
|
|
57
64
|
|
|
65
|
+
it "should try an exact match" do
|
|
66
|
+
subject.find_by_title(cart.title).should == cart
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should try a match with default normalizer" do
|
|
70
|
+
subject.find_by_title(cart.title.upcase).should == cart
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "should return nil when no cart matchs" do
|
|
74
|
+
subject.find_by_title("nothing").should be_nil
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should return nil when several carts match" do
|
|
78
|
+
carts << cart
|
|
79
|
+
subject.find_by_title(cart.title).should be_nil
|
|
80
|
+
end
|
|
81
|
+
|
|
58
82
|
end
|
|
59
83
|
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
describe Rivendell::Import::CartFinder::ByApi do
|
|
87
|
+
|
|
88
|
+
let(:cart_finder) { Rivendell::Import::CartFinder::ByApi.new(xport) }
|
|
89
|
+
subject { cart_finder }
|
|
90
|
+
|
|
91
|
+
let(:xport) { mock }
|
|
92
|
+
|
|
93
|
+
let(:cart) { mock :title => "dummy" }
|
|
94
|
+
let(:carts) { [ cart ] }
|
|
95
|
+
|
|
60
96
|
describe "#carts" do
|
|
61
97
|
|
|
62
98
|
before do
|
|
@@ -82,27 +118,29 @@ describe Rivendell::Import::CartsCache do
|
|
|
82
118
|
|
|
83
119
|
end
|
|
84
120
|
|
|
85
|
-
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
describe Rivendell::Import::CartFinder::ByDb do
|
|
124
|
+
|
|
125
|
+
let(:cart_finder) { Rivendell::Import::CartFinder::ByDb.new }
|
|
126
|
+
subject { cart_finder }
|
|
127
|
+
|
|
128
|
+
let(:cart) { mock :title => "dummy" }
|
|
129
|
+
let(:carts) { [ cart ] }
|
|
130
|
+
|
|
131
|
+
describe "#carts" do
|
|
86
132
|
|
|
87
133
|
before do
|
|
88
|
-
|
|
134
|
+
Rivendell::DB::Cart.stub :all => carts
|
|
89
135
|
end
|
|
90
136
|
|
|
91
|
-
it "should
|
|
92
|
-
subject.
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "should try a match with default normalizer" do
|
|
96
|
-
subject.find_by_title(cart.title.upcase).should == cart
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should return nil when no cart matchs" do
|
|
100
|
-
subject.find_by_title("nothing").should be_nil
|
|
137
|
+
it "should return Carts found in database" do
|
|
138
|
+
subject.carts.should == carts
|
|
101
139
|
end
|
|
102
140
|
|
|
103
|
-
it "should
|
|
104
|
-
|
|
105
|
-
subject.
|
|
141
|
+
it "should search in specified group if present" do
|
|
142
|
+
Rivendell::DB::Cart.should_receive(:all).with(hash_including(:group_name => "dummy")).and_return(carts)
|
|
143
|
+
subject.carts(:group => "dummy")
|
|
106
144
|
end
|
|
107
145
|
|
|
108
146
|
end
|
|
@@ -280,4 +280,25 @@ describe Rivendell::Import::Task do
|
|
|
280
280
|
|
|
281
281
|
end
|
|
282
282
|
|
|
283
|
+
describe ".purge!" do
|
|
284
|
+
|
|
285
|
+
it "should remove tasks older than 24 hours" do
|
|
286
|
+
old_task = Rivendell::Import::Task.create! :file => file, :created_at => 25.hours.ago
|
|
287
|
+
Rivendell::Import::Task.purge!
|
|
288
|
+
Rivendell::Import::Task.exists?(old_task).should be_false
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
it "should keep recent tasks" do
|
|
292
|
+
task = Rivendell::Import::Task.create! :file => file
|
|
293
|
+
Rivendell::Import::Task.purge!
|
|
294
|
+
Rivendell::Import::Task.exists?(task).should be_true
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "should be invoked each time a new Task is created" do
|
|
298
|
+
Rivendell::Import::Task.should_receive(:purge!)
|
|
299
|
+
Rivendell::Import::Task.create! :file => file
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
end
|
|
303
|
+
|
|
283
304
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rivendell-import
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,24 +9,24 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-07-02 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: listen
|
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - ~>
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version:
|
|
21
|
+
version: 1.2.1
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
none: false
|
|
26
26
|
requirements:
|
|
27
|
-
- -
|
|
27
|
+
- - ~>
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
29
|
+
version: 1.2.1
|
|
30
30
|
- !ruby/object:Gem::Dependency
|
|
31
31
|
name: httmultiparty
|
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -203,6 +203,22 @@ dependencies:
|
|
|
203
203
|
- - ! '>='
|
|
204
204
|
- !ruby/object:Gem::Version
|
|
205
205
|
version: '0'
|
|
206
|
+
- !ruby/object:Gem::Dependency
|
|
207
|
+
name: rivendell-db
|
|
208
|
+
requirement: !ruby/object:Gem::Requirement
|
|
209
|
+
none: false
|
|
210
|
+
requirements:
|
|
211
|
+
- - ! '>='
|
|
212
|
+
- !ruby/object:Gem::Version
|
|
213
|
+
version: '0'
|
|
214
|
+
type: :runtime
|
|
215
|
+
prerelease: false
|
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
217
|
+
none: false
|
|
218
|
+
requirements:
|
|
219
|
+
- - ! '>='
|
|
220
|
+
- !ruby/object:Gem::Version
|
|
221
|
+
version: '0'
|
|
206
222
|
- !ruby/object:Gem::Dependency
|
|
207
223
|
name: simplecov
|
|
208
224
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -364,7 +380,8 @@ files:
|
|
|
364
380
|
- lib/rivendell/import/application.rb
|
|
365
381
|
- lib/rivendell/import/base.rb
|
|
366
382
|
- lib/rivendell/import/cart.rb
|
|
367
|
-
- lib/rivendell/import/
|
|
383
|
+
- lib/rivendell/import/cart_finder.rb
|
|
384
|
+
- lib/rivendell/import/cart_finder_by_db.rb
|
|
368
385
|
- lib/rivendell/import/cli.rb
|
|
369
386
|
- lib/rivendell/import/config.rb
|
|
370
387
|
- lib/rivendell/import/config_loader.rb
|
|
@@ -393,8 +410,8 @@ files:
|
|
|
393
410
|
- rivendell-import.gemspec
|
|
394
411
|
- spec/fixtures/mail-body.erb
|
|
395
412
|
- spec/rivendell/import/base_spec.rb
|
|
413
|
+
- spec/rivendell/import/cart_finder_spec.rb
|
|
396
414
|
- spec/rivendell/import/cart_spec.rb
|
|
397
|
-
- spec/rivendell/import/carts_cache_spec.rb
|
|
398
415
|
- spec/rivendell/import/cli_spec.rb
|
|
399
416
|
- spec/rivendell/import/config_spec.rb
|
|
400
417
|
- spec/rivendell/import/context_spec.rb
|
|
@@ -429,7 +446,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
429
446
|
version: '0'
|
|
430
447
|
segments:
|
|
431
448
|
- 0
|
|
432
|
-
hash:
|
|
449
|
+
hash: 3691791623266021807
|
|
433
450
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
434
451
|
none: false
|
|
435
452
|
requirements:
|
|
@@ -438,7 +455,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
438
455
|
version: '0'
|
|
439
456
|
segments:
|
|
440
457
|
- 0
|
|
441
|
-
hash:
|
|
458
|
+
hash: 3691791623266021807
|
|
442
459
|
requirements: []
|
|
443
460
|
rubyforge_project:
|
|
444
461
|
rubygems_version: 1.8.23
|
|
@@ -453,8 +470,8 @@ test_files:
|
|
|
453
470
|
- features/support/mock_xport.rb
|
|
454
471
|
- spec/fixtures/mail-body.erb
|
|
455
472
|
- spec/rivendell/import/base_spec.rb
|
|
473
|
+
- spec/rivendell/import/cart_finder_spec.rb
|
|
456
474
|
- spec/rivendell/import/cart_spec.rb
|
|
457
|
-
- spec/rivendell/import/carts_cache_spec.rb
|
|
458
475
|
- spec/rivendell/import/cli_spec.rb
|
|
459
476
|
- spec/rivendell/import/config_spec.rb
|
|
460
477
|
- spec/rivendell/import/context_spec.rb
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
module Rivendell::Import
|
|
2
|
-
class CartsCache
|
|
3
|
-
|
|
4
|
-
attr_accessor :xport
|
|
5
|
-
|
|
6
|
-
def initialize(xport)
|
|
7
|
-
@xport = xport
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def find_all_by_title(string, options = {})
|
|
11
|
-
normalizer = options.delete(:normalizer) || Proc.new { |id| id }
|
|
12
|
-
|
|
13
|
-
string = normalizer.call(string)
|
|
14
|
-
carts(options).select do |cart|
|
|
15
|
-
normalizer.call(cart.title) == string
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def default_normalizer
|
|
20
|
-
Proc.new do |string|
|
|
21
|
-
string.downcase.gsub(/[^a-z0-9]/," ").gsub(/[ ]+/," ")
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def find_by_title(string, options = {})
|
|
26
|
-
matching_carts = find_all_by_title(string, options)
|
|
27
|
-
|
|
28
|
-
if matching_carts.blank?
|
|
29
|
-
matching_carts = find_all_by_title(string, options.merge(:normalizer => default_normalizer))
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
matching_carts.first if matching_carts.one?
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def cache
|
|
36
|
-
clear if purged_at < time_to_live.ago
|
|
37
|
-
@cache ||= {}
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def clear
|
|
41
|
-
@cache = nil
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
@@time_to_live = 600
|
|
45
|
-
cattr_accessor :time_to_live
|
|
46
|
-
|
|
47
|
-
attr_accessor :purged_at
|
|
48
|
-
|
|
49
|
-
def purged_at
|
|
50
|
-
@purged_at ||= Time.now
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def carts(options = {})
|
|
54
|
-
cache[options.to_s] ||= xport.list_carts(options)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
end
|