LittleWeasel 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/Jenkinsfile +20 -0
- data/LittleWeasel.gemspec +3 -3
- data/README.md +1 -1
- data/lib/LittleWeasel/dictionary_key.rb +2 -2
- data/lib/LittleWeasel/dictionary_manager.rb +10 -4
- data/lib/LittleWeasel/metadata/metadatable.rb +5 -7
- data/lib/LittleWeasel/modules/dictionary_cache_validatable.rb +3 -5
- data/lib/LittleWeasel/modules/dictionary_key_validatable.rb +3 -5
- data/lib/LittleWeasel/modules/dictionary_metadata_validatable.rb +3 -5
- data/lib/LittleWeasel/modules/dictionary_source_validatable.rb +15 -0
- data/lib/LittleWeasel/modules/dictionary_sourceable.rb +66 -6
- data/lib/LittleWeasel/modules/dictionary_validatable.rb +0 -12
- data/lib/LittleWeasel/modules/language.rb +10 -9
- data/lib/LittleWeasel/modules/language_validatable.rb +2 -4
- data/lib/LittleWeasel/modules/locale.rb +7 -24
- data/lib/LittleWeasel/modules/order_validatable.rb +3 -5
- data/lib/LittleWeasel/modules/region.rb +10 -9
- data/lib/LittleWeasel/modules/region_validatable.rb +2 -4
- data/lib/LittleWeasel/modules/tag_validatable.rb +2 -4
- data/lib/LittleWeasel/preprocessors/preprocessed_word.rb +1 -0
- data/lib/LittleWeasel/preprocessors/preprocessed_word_validatable.rb +1 -0
- data/lib/LittleWeasel/preprocessors/preprocessed_words.rb +6 -2
- data/lib/LittleWeasel/preprocessors/preprocessed_words_validatable.rb +1 -0
- data/lib/LittleWeasel/preprocessors/word_preprocessor.rb +1 -0
- data/lib/LittleWeasel/services/dictionary_cache_service.rb +11 -62
- data/lib/LittleWeasel/services/dictionary_creator_service.rb +2 -2
- data/lib/LittleWeasel/services/dictionary_file_loader_service.rb +1 -1
- data/lib/LittleWeasel/services/dictionary_metadata_service.rb +4 -2
- data/lib/LittleWeasel/version.rb +1 -1
- data/spec/factories/dictionary_cache_service.rb +2 -2
- data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +52 -2
- data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +1 -1
- data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +56 -19
- data/spec/lib/LittleWeasel/modules/language_spec.rb +65 -5
- data/spec/lib/LittleWeasel/modules/locale_spec.rb +4 -49
- data/spec/lib/LittleWeasel/modules/region_spec.rb +65 -5
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +28 -2
- data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +43 -0
- data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +25 -25
- data/spec/support/file_helpers.rb +17 -3
- data/spec/support/shared_contexts.rb +0 -1
- metadata +12 -15
- data/lib/LittleWeasel/modules/dictionary_loader_servicable.rb +0 -27
- data/lib/LittleWeasel/services/dictionary_loader_service.rb +0 -59
- data/spec/factories/dictionary_loader_service.rb +0 -14
- data/spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb +0 -50
@@ -11,8 +11,6 @@ RSpec.describe LittleWeasel::Preprocessors::WordPreprocessorManagable, type: :mo
|
|
11
11
|
include WordPreprocessorManagable
|
12
12
|
end
|
13
13
|
|
14
|
-
subject { MockSubject.new }
|
15
|
-
|
16
14
|
class MockWordPreprocessor01 < LittleWeasel::Preprocessors::WordPreprocessor
|
17
15
|
def initialize(order: 0)
|
18
16
|
super order: order
|
@@ -153,6 +151,34 @@ RSpec.describe LittleWeasel::Preprocessors::WordPreprocessorManagable, type: :mo
|
|
153
151
|
expect(subject.word_preprocessors).to eq expected_results
|
154
152
|
end
|
155
153
|
end
|
154
|
+
|
155
|
+
context 'when passing a nil argument' do
|
156
|
+
before do
|
157
|
+
subject.clear_preprocessors
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when a block is provided' do
|
161
|
+
it 'does NOT raise an error' do
|
162
|
+
expect do
|
163
|
+
subject.add_preprocessors { |_word_preprocessors| }
|
164
|
+
end.to_not raise_error
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'uses the word preprocessors added via the block' do
|
168
|
+
expect do
|
169
|
+
subject.add_preprocessors do |word_preprocessors|
|
170
|
+
word_preprocessors.concat word_preprocessors_01_thru_03
|
171
|
+
end
|
172
|
+
end.to change { subject.word_preprocessors.count }.from(0).to(3)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context 'when a block is NOT provided' do
|
177
|
+
it 'raises an error' do
|
178
|
+
expect { subject.add_preprocessors }.to raise_error('A block is required if argument word_preprocessors is nil')
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
156
182
|
end
|
157
183
|
|
158
184
|
#replace_preprocessors
|
@@ -84,6 +84,20 @@ RSpec.describe LittleWeasel::Preprocessors::WordPreprocessor do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
#preprocessor_on!
|
88
|
+
describe '#preprocessor_on!' do
|
89
|
+
before do
|
90
|
+
expect(subject.preprocessor_off?).to eq true
|
91
|
+
end
|
92
|
+
|
93
|
+
let(:preprocessor_on) { false }
|
94
|
+
|
95
|
+
it 'turns the preprocessor on' do
|
96
|
+
subject.preprocessor_on!
|
97
|
+
expect(subject.preprocessor_on).to eq true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
87
101
|
#preprocessor_on?
|
88
102
|
describe '#preprocessor_on?' do
|
89
103
|
context 'when #preprocessor_on is true' do
|
@@ -172,4 +186,33 @@ RSpec.describe LittleWeasel::Preprocessors::WordPreprocessor do
|
|
172
186
|
end
|
173
187
|
end
|
174
188
|
end
|
189
|
+
|
190
|
+
#preprocessor_off?
|
191
|
+
describe '#preprocessor_off?' do
|
192
|
+
context 'when #preprocessor_on is false' do
|
193
|
+
let(:preprocessor_on) { false }
|
194
|
+
|
195
|
+
it 'returns true' do
|
196
|
+
expect(subject.preprocessor_off?).to eq true
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'when #preprocessor_on is true' do
|
201
|
+
it 'returns false' do
|
202
|
+
expect(subject.preprocessor_off?).to eq false
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
#preprocessor_off!
|
208
|
+
describe '#preprocessor_off!' do
|
209
|
+
before do
|
210
|
+
expect(subject.preprocessor_on?).to eq true
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'turns the preprocessor off' do
|
214
|
+
subject.preprocessor_off!
|
215
|
+
expect(subject.preprocessor_on).to eq false
|
216
|
+
end
|
217
|
+
end
|
175
218
|
end
|
@@ -58,7 +58,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
58
58
|
|
59
59
|
context 'when passing a NON-initialized dictionary cache Hash' do
|
60
60
|
before do
|
61
|
-
subject.add_dictionary_source
|
61
|
+
subject.add_dictionary_source dictionary_source: file
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'returns false' do
|
@@ -122,9 +122,9 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
122
122
|
|
123
123
|
before do
|
124
124
|
create(:dictionary_cache_service, dictionary_key: en_us_dictionary_key, dictionary_cache: dictionary_cache)
|
125
|
-
.add_dictionary_source
|
125
|
+
.add_dictionary_source dictionary_source: memory_source
|
126
126
|
create(:dictionary_cache_service, dictionary_key: en_gb_dictionary_key, dictionary_cache: dictionary_cache)
|
127
|
-
.add_dictionary_source
|
127
|
+
.add_dictionary_source dictionary_source: dictionary_path_for(file_name: en_gb_dictionary_key.key)
|
128
128
|
end
|
129
129
|
|
130
130
|
it 'returns false' do
|
@@ -140,18 +140,18 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
#add_dictionary_source
|
144
|
-
describe '#add_dictionary_source
|
143
|
+
#add_dictionary_source dictionary_source: memory_source
|
144
|
+
describe '#add_dictionary_source dictionary_source: memory_source' do
|
145
145
|
subject! do
|
146
146
|
create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_key: dictionary_key)
|
147
|
-
.add_dictionary_source
|
147
|
+
.add_dictionary_source dictionary_source: memory_source
|
148
148
|
end
|
149
149
|
|
150
150
|
context 'when a dictionary already exists' do
|
151
151
|
it 'raises an error' do
|
152
152
|
expect do
|
153
153
|
create(:dictionary_cache_service, dictionary_key: dictionary_key, dictionary_cache: subject.dictionary_cache)
|
154
|
-
.add_dictionary_source
|
154
|
+
.add_dictionary_source dictionary_source: memory_source
|
155
155
|
end.to raise_error "The dictionary source associated with key '#{key}' already exists."
|
156
156
|
end
|
157
157
|
end
|
@@ -162,7 +162,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
162
162
|
end
|
163
163
|
|
164
164
|
before do
|
165
|
-
dictionary_cache_service.add_dictionary_source
|
165
|
+
dictionary_cache_service.add_dictionary_source dictionary_source: memory_source
|
166
166
|
end
|
167
167
|
|
168
168
|
let(:dictionary_source) { dictionary_cache_service.dictionary_source }
|
@@ -180,7 +180,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
180
180
|
describe 'maintains dictionary_cache object integrity' do
|
181
181
|
it_behaves_like 'the dictionary_cache object reference has not changed' do
|
182
182
|
subject { create(:dictionary_cache_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache) }
|
183
|
-
let(:actual_dictionary_cache) { subject.add_dictionary_source(
|
183
|
+
let(:actual_dictionary_cache) { subject.add_dictionary_source(dictionary_source: memory_source).dictionary_cache }
|
184
184
|
let(:expected_dictionary_cache) { dictionary_cache }
|
185
185
|
end
|
186
186
|
end
|
@@ -191,13 +191,13 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
191
191
|
context 'when a dictionary reference for the key already exists' do
|
192
192
|
before do
|
193
193
|
create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_key: dictionary_key)
|
194
|
-
.add_dictionary_source(
|
194
|
+
.add_dictionary_source(dictionary_source: file)
|
195
195
|
end
|
196
196
|
|
197
197
|
it 'raises an error' do
|
198
198
|
expect do
|
199
199
|
create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_key: dictionary_key, dictionary_cache: subject.dictionary_cache)
|
200
|
-
.add_dictionary_source(
|
200
|
+
.add_dictionary_source(dictionary_source: file)
|
201
201
|
end.to raise_error "The dictionary source associated with key '#{key}' already exists."
|
202
202
|
end
|
203
203
|
end
|
@@ -205,7 +205,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
205
205
|
context 'when a dictionary reference for the key DOES NOT already exist' do
|
206
206
|
subject! do
|
207
207
|
create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_key: dictionary_key)
|
208
|
-
.add_dictionary_source(
|
208
|
+
.add_dictionary_source(dictionary_source: file)
|
209
209
|
end
|
210
210
|
|
211
211
|
let(:en_gb_file) do
|
@@ -214,7 +214,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
214
214
|
|
215
215
|
it 'creates a new dictionary reference' do
|
216
216
|
dictionary_cache_service = create(:dictionary_cache_service, dictionary_key: en_gb_dictionary_key, dictionary_cache: subject.dictionary_cache)
|
217
|
-
dictionary_cache_service.add_dictionary_source
|
217
|
+
dictionary_cache_service.add_dictionary_source dictionary_source: en_gb_file
|
218
218
|
expect(dictionary_cache_service.dictionary_reference?).to eq true
|
219
219
|
end
|
220
220
|
|
@@ -223,7 +223,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
223
223
|
dictionary_cache_service = create(:dictionary_cache_service, dictionary_key: en_gb_dictionary_key, dictionary_cache: subject.dictionary_cache)
|
224
224
|
# Note: We're using the same file as en-US dictionary key, so
|
225
225
|
# the file source is NOT unique and will be reused.
|
226
|
-
dictionary_cache_service.add_dictionary_source
|
226
|
+
dictionary_cache_service.add_dictionary_source dictionary_source: file
|
227
227
|
expect(LittleWeasel::Modules::DictionarySourceable.file_source? dictionary_cache_service.dictionary_source).to be_truthy
|
228
228
|
expect(dictionary_cache_service.dictionary_source == subject.dictionary_source).to eq true
|
229
229
|
end
|
@@ -234,7 +234,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
234
234
|
dictionary_cache_service = create(:dictionary_cache_service, dictionary_key: en_gb_dictionary_key, dictionary_cache: subject.dictionary_cache)
|
235
235
|
# Note: We're using file that is DIFFERENT from the file being used by the
|
236
236
|
# en-US dictionary key, the file source created will be unique.
|
237
|
-
dictionary_cache_service.add_dictionary_source
|
237
|
+
dictionary_cache_service.add_dictionary_source dictionary_source: en_gb_file
|
238
238
|
expect(LittleWeasel::Modules::DictionarySourceable.file_source? dictionary_cache_service.dictionary_source).to be_truthy
|
239
239
|
expect(dictionary_cache_service.dictionary_source == subject.dictionary_source).to eq false
|
240
240
|
end
|
@@ -244,7 +244,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
244
244
|
describe 'maintains dictionary_cache object integrity' do
|
245
245
|
it_behaves_like 'the dictionary_cache object reference has not changed' do
|
246
246
|
subject { create(:dictionary_cache_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache) }
|
247
|
-
let(:actual_dictionary_cache) { subject.add_dictionary_source(
|
247
|
+
let(:actual_dictionary_cache) { subject.add_dictionary_source(dictionary_source: file).dictionary_cache }
|
248
248
|
let(:expected_dictionary_cache) { dictionary_cache }
|
249
249
|
end
|
250
250
|
end
|
@@ -253,7 +253,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
253
253
|
#dictionary_file
|
254
254
|
describe '#dictionary_file' do
|
255
255
|
context 'when a file source is used' do
|
256
|
-
subject! { create(:dictionary_cache_service, dictionary_key: dictionary_key).add_dictionary_source(
|
256
|
+
subject! { create(:dictionary_cache_service, dictionary_key: dictionary_key).add_dictionary_source(dictionary_source: file) }
|
257
257
|
|
258
258
|
it 'returns the dictionary file' do
|
259
259
|
expect(subject.dictionary_file).to eq file
|
@@ -261,7 +261,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
261
261
|
end
|
262
262
|
|
263
263
|
context 'when a memory source is used' do
|
264
|
-
subject! { create(:dictionary_cache_service, dictionary_key: dictionary_key).add_dictionary_source
|
264
|
+
subject! { create(:dictionary_cache_service, dictionary_key: dictionary_key).add_dictionary_source dictionary_source: memory_source }
|
265
265
|
|
266
266
|
let(:dictionary_words) { dictionary_words_for(dictionary_file_path: file) }
|
267
267
|
|
@@ -275,7 +275,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
275
275
|
describe '#dictionary_id' do
|
276
276
|
context 'when a dictionary id exists for the given dictionary key' do
|
277
277
|
before do
|
278
|
-
subject.add_dictionary_source
|
278
|
+
subject.add_dictionary_source dictionary_source: memory_source
|
279
279
|
end
|
280
280
|
|
281
281
|
it 'returns the key' do
|
@@ -309,13 +309,13 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
312
|
-
#
|
313
|
-
describe '#
|
312
|
+
#dictionary_exist?
|
313
|
+
describe '#dictionary_exist?' do
|
314
314
|
context 'when the dictionary reference does not exist' do
|
315
315
|
subject { create(:dictionary_cache_service, dictionary_cache: dictionary_cache) }
|
316
316
|
|
317
317
|
it 'returns false' do
|
318
|
-
expect(subject.
|
318
|
+
expect(subject.dictionary_exist?).to eq false
|
319
319
|
end
|
320
320
|
end
|
321
321
|
|
@@ -323,7 +323,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
323
323
|
subject { create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_file_source: true, load: true) }
|
324
324
|
|
325
325
|
it 'returns true' do
|
326
|
-
expect(subject.
|
326
|
+
expect(subject.dictionary_exist?).to eq true
|
327
327
|
end
|
328
328
|
end
|
329
329
|
|
@@ -331,7 +331,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
331
331
|
subject { create(:dictionary_cache_service, dictionary_cache: dictionary_cache, dictionary_file_source: true) }
|
332
332
|
|
333
333
|
it 'returns false' do
|
334
|
-
expect(subject.
|
334
|
+
expect(subject.dictionary_exist?).to eq false
|
335
335
|
end
|
336
336
|
end
|
337
337
|
end
|
@@ -374,7 +374,7 @@ RSpec.describe LittleWeasel::Services::DictionaryCacheService do
|
|
374
374
|
|
375
375
|
it 'returns the dictionary cache for the dictionary' do
|
376
376
|
expect(subject.dictionary_reference?).to eq true
|
377
|
-
expect(subject.
|
377
|
+
expect(subject.dictionary_exist?).to eq true
|
378
378
|
expect(subject.dictionary_object!).to be_kind_of LittleWeasel::Dictionary
|
379
379
|
end
|
380
380
|
end
|
@@ -4,18 +4,32 @@ require_relative '../../lib/LittleWeasel/modules/locale'
|
|
4
4
|
|
5
5
|
module Support
|
6
6
|
# This module contains methods to help with dictionary files.
|
7
|
-
|
7
|
+
|
8
|
+
class Locale
|
8
9
|
include LittleWeasel::Modules::Locale
|
9
10
|
|
11
|
+
attr_accessor :language, :region
|
12
|
+
|
13
|
+
def initialize(language:, region:)
|
14
|
+
self.language = language
|
15
|
+
self.region = region
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module FileHelpers
|
10
20
|
module_function
|
11
21
|
|
22
|
+
def locale_for(language:, region: nil)
|
23
|
+
Locale.new(language: language, region: region).locale
|
24
|
+
end
|
25
|
+
|
12
26
|
def region_dictionary_path language:, region:
|
13
|
-
file_name =
|
27
|
+
file_name = locale_for language: language, region: region
|
14
28
|
dictionary_path_for file_name: file_name
|
15
29
|
end
|
16
30
|
|
17
31
|
def language_dictionary_path language:
|
18
|
-
file_name =
|
32
|
+
file_name = locale_for language: language
|
19
33
|
dictionary_path_for file_name: file_name
|
20
34
|
end
|
21
35
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LittleWeasel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gene M. Angelo, Jr.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -96,16 +96,16 @@ dependencies:
|
|
96
96
|
name: rake
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
|
-
- - "
|
99
|
+
- - ">="
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version:
|
101
|
+
version: 12.3.3
|
102
102
|
type: :development
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- - "
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
108
|
+
version: 12.3.3
|
109
109
|
- !ruby/object:Gem::Dependency
|
110
110
|
name: redcarpet
|
111
111
|
requirement: !ruby/object:Gem::Requirement
|
@@ -250,7 +250,8 @@ dependencies:
|
|
250
250
|
- - "~>"
|
251
251
|
- !ruby/object:Gem::Version
|
252
252
|
version: 0.9.26
|
253
|
-
description:
|
253
|
+
description: Spellchecker+ with preprocessing and filtering for single and multiple
|
254
|
+
word blocks.
|
254
255
|
email:
|
255
256
|
- public.gma@gmail.com
|
256
257
|
executables: []
|
@@ -277,6 +278,7 @@ files:
|
|
277
278
|
- ".yardopts"
|
278
279
|
- CHANGELOG.md
|
279
280
|
- Gemfile
|
281
|
+
- Jenkinsfile
|
280
282
|
- LICENSE.txt
|
281
283
|
- LittleWeasel.gemspec
|
282
284
|
- README.md
|
@@ -317,9 +319,9 @@ files:
|
|
317
319
|
- lib/LittleWeasel/modules/dictionary_file_loader.rb
|
318
320
|
- lib/LittleWeasel/modules/dictionary_key_validatable.rb
|
319
321
|
- lib/LittleWeasel/modules/dictionary_keyable.rb
|
320
|
-
- lib/LittleWeasel/modules/dictionary_loader_servicable.rb
|
321
322
|
- lib/LittleWeasel/modules/dictionary_metadata_servicable.rb
|
322
323
|
- lib/LittleWeasel/modules/dictionary_metadata_validatable.rb
|
324
|
+
- lib/LittleWeasel/modules/dictionary_source_validatable.rb
|
323
325
|
- lib/LittleWeasel/modules/dictionary_sourceable.rb
|
324
326
|
- lib/LittleWeasel/modules/dictionary_validatable.rb
|
325
327
|
- lib/LittleWeasel/modules/language.rb
|
@@ -346,7 +348,6 @@ files:
|
|
346
348
|
- lib/LittleWeasel/services/dictionary_creator_service.rb
|
347
349
|
- lib/LittleWeasel/services/dictionary_file_loader_service.rb
|
348
350
|
- lib/LittleWeasel/services/dictionary_killer_service.rb
|
349
|
-
- lib/LittleWeasel/services/dictionary_loader_service.rb
|
350
351
|
- lib/LittleWeasel/services/dictionary_metadata_service.rb
|
351
352
|
- lib/LittleWeasel/services/invalid_words_service.rb
|
352
353
|
- lib/LittleWeasel/version.rb
|
@@ -358,7 +359,6 @@ files:
|
|
358
359
|
- spec/factories/dictionary_hash.rb
|
359
360
|
- spec/factories/dictionary_key.rb
|
360
361
|
- spec/factories/dictionary_killer_service.rb
|
361
|
-
- spec/factories/dictionary_loader_service.rb
|
362
362
|
- spec/factories/dictionary_manager.rb
|
363
363
|
- spec/factories/dictionary_metadata.rb
|
364
364
|
- spec/factories/dictionary_metadata_service.rb
|
@@ -403,7 +403,6 @@ files:
|
|
403
403
|
- spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb
|
404
404
|
- spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb
|
405
405
|
- spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb
|
406
|
-
- spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb
|
407
406
|
- spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb
|
408
407
|
- spec/lib/LittleWeasel/word_results_spec.rb
|
409
408
|
- spec/lib/LittleWeasel/workflow/workflow_spec.rb
|
@@ -445,8 +444,8 @@ requirements: []
|
|
445
444
|
rubygems_version: 3.2.15
|
446
445
|
signing_key:
|
447
446
|
specification_version: 4
|
448
|
-
summary:
|
449
|
-
|
447
|
+
summary: Checks a word or group of words for validity against a dictionary/ies provided.
|
448
|
+
Word filtering and word preprocessing is available.
|
450
449
|
test_files:
|
451
450
|
- spec/factories/dictionary.rb
|
452
451
|
- spec/factories/dictionary_cache_service.rb
|
@@ -455,7 +454,6 @@ test_files:
|
|
455
454
|
- spec/factories/dictionary_hash.rb
|
456
455
|
- spec/factories/dictionary_key.rb
|
457
456
|
- spec/factories/dictionary_killer_service.rb
|
458
|
-
- spec/factories/dictionary_loader_service.rb
|
459
457
|
- spec/factories/dictionary_manager.rb
|
460
458
|
- spec/factories/dictionary_metadata.rb
|
461
459
|
- spec/factories/dictionary_metadata_service.rb
|
@@ -500,7 +498,6 @@ test_files:
|
|
500
498
|
- spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb
|
501
499
|
- spec/lib/LittleWeasel/services/dictionary_creator_service_spec.rb
|
502
500
|
- spec/lib/LittleWeasel/services/dictionary_file_loader_service_spec.rb
|
503
|
-
- spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb
|
504
501
|
- spec/lib/LittleWeasel/services/dictionary_metadata_service_spec.rb
|
505
502
|
- spec/lib/LittleWeasel/word_results_spec.rb
|
506
503
|
- spec/lib/LittleWeasel/workflow/workflow_spec.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../dictionary_key'
|
4
|
-
require_relative '../services/dictionary_loader_service'
|
5
|
-
require_relative 'dictionary_cache_validatable'
|
6
|
-
|
7
|
-
module LittleWeasel
|
8
|
-
module Modules
|
9
|
-
# This module defines methods and attributes to consume the dictionary
|
10
|
-
# loader service.
|
11
|
-
module DictionaryLoaderServicable
|
12
|
-
include DictionaryCacheValidatable
|
13
|
-
include DictionaryKeyable
|
14
|
-
|
15
|
-
attr_reader :dictionary_cache, :dictionary_key, :dictionary_metadata
|
16
|
-
|
17
|
-
def dictionary_loader_service
|
18
|
-
Services::DictionaryLoaderService.new(dictionary_key: dictionary_key, dictionary_cache: dictionary_cache,
|
19
|
-
dictionary_metadata: dictionary_metadata)
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_writer :dictionary_cache, :dictionary_key, :dictionary_metadata
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../dictionary'
|
4
|
-
require_relative '../metadata/dictionary_metadata'
|
5
|
-
require_relative '../modules/dictionary_cache_servicable'
|
6
|
-
require_relative '../modules/dictionary_metadata_servicable'
|
7
|
-
require_relative '../modules/dictionary_keyable'
|
8
|
-
require_relative 'dictionary_file_loader_service'
|
9
|
-
|
10
|
-
module LittleWeasel
|
11
|
-
module Services
|
12
|
-
# This class provides services to load dictionaries from either disk (if
|
13
|
-
# the dictionary has not been loaded) or from the dictionary cache if the
|
14
|
-
# dictionary has already been loaded from disk.
|
15
|
-
class DictionaryLoaderService
|
16
|
-
include Modules::DictionaryKeyable
|
17
|
-
include Modules::DictionaryCacheServicable
|
18
|
-
include Modules::DictionaryMetadataServicable
|
19
|
-
|
20
|
-
def initialize(dictionary_key:, dictionary_cache:, dictionary_metadata:)
|
21
|
-
validate_dictionary_key dictionary_key: dictionary_key
|
22
|
-
self.dictionary_key = dictionary_key
|
23
|
-
|
24
|
-
validate_dictionary_cache dictionary_cache: dictionary_cache
|
25
|
-
self.dictionary_cache = dictionary_cache
|
26
|
-
|
27
|
-
validate_dictionary_metadata dictionary_metadata: dictionary_metadata
|
28
|
-
self.dictionary_metadata = dictionary_metadata
|
29
|
-
end
|
30
|
-
|
31
|
-
def execute
|
32
|
-
if dictionary_cache_service.dictionary_exists?
|
33
|
-
load_from_cache
|
34
|
-
else
|
35
|
-
dictionary_cache_service.dictionary_object = load_from_disk
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def load_from_cache
|
42
|
-
dictionary_cache_service.dictionary_object!
|
43
|
-
end
|
44
|
-
|
45
|
-
def load_from_disk
|
46
|
-
dictionary_for dictionary_words: dictionary_file_loader_service.execute
|
47
|
-
end
|
48
|
-
|
49
|
-
def dictionary_for(dictionary_words:)
|
50
|
-
Dictionary.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache,
|
51
|
-
dictionary_metadata: dictionary_metadata, dictionary_words: dictionary_words
|
52
|
-
end
|
53
|
-
|
54
|
-
def dictionary_file_loader_service
|
55
|
-
Services::DictionaryFileLoaderService.new dictionary_key: dictionary_key, dictionary_cache: dictionary_cache
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
|
3
|
-
FactoryBot.define do
|
4
|
-
factory :dictionary_loader_service, class: LittleWeasel::Services::DictionaryLoaderService do
|
5
|
-
dictionary_key { create(:dictionary_key) }
|
6
|
-
dictionary_cache { {} }
|
7
|
-
dictionary_metadata { {} }
|
8
|
-
|
9
|
-
skip_create
|
10
|
-
initialize_with do
|
11
|
-
new(dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
RSpec.describe LittleWeasel::Services::DictionaryLoaderService do
|
6
|
-
subject { create(:dictionary_loader_service, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache, dictionary_metadata: dictionary_metadata) }
|
7
|
-
|
8
|
-
let(:language) { :en }
|
9
|
-
let(:region) { :us }
|
10
|
-
let(:tag) {}
|
11
|
-
let(:dictionary_key) { create(:dictionary_key, language: language, region: region, tag: tag) }
|
12
|
-
let(:dictionary_cache) { {} }
|
13
|
-
let(:dictionary_metadata) { {} }
|
14
|
-
|
15
|
-
#execute
|
16
|
-
describe '#execute' do
|
17
|
-
context 'when loading dictionaries created from a file' do
|
18
|
-
let!(:dictionary_cache_service) { create(:dictionary_cache_service, dictionary_file_source: true, dictionary_key: dictionary_key, dictionary_cache: dictionary_cache) }
|
19
|
-
|
20
|
-
context 'when the dictionary is not cached' do
|
21
|
-
it 'loads the dictionary file and returns the Dictionary' do
|
22
|
-
expect(dictionary_cache_service.dictionary_exists?).to be false
|
23
|
-
# Remove this line; there is a bug in SimpleCov that will not
|
24
|
-
# recognize #load_from_cache as having test coverage if we
|
25
|
-
# stub this out :(
|
26
|
-
# expect(subject).to_not receive(:load_from_cache)
|
27
|
-
expect(subject.execute).to be_kind_of LittleWeasel::Dictionary
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when the dictionary is cached' do
|
32
|
-
before do
|
33
|
-
# This will load the dictionary from disk, and cache it in
|
34
|
-
# the dictionary cache; the DictionaryLoaderService loads
|
35
|
-
# the dictionary into the dictionary cache if loaded from disk.
|
36
|
-
subject.execute
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'loads the dictionary from the dictionary cache and returns the Dictionary' do
|
40
|
-
expect(dictionary_cache_service.dictionary_exists?).to be true
|
41
|
-
# Remove this line; there is a bug in SimpleCov that will not
|
42
|
-
# recognize #load_from_cache as having test coverage if we
|
43
|
-
# stub this out :(
|
44
|
-
# expect(subject).to receive(:load_from_cache).and_return(dictionary_cache_service.dictionary_object!)
|
45
|
-
expect(subject.execute).to be dictionary_cache_service.dictionary_object!
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|