LittleWeasel 4.0.0 → 5.0.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -1
  3. data/Jenkinsfile +20 -0
  4. data/LittleWeasel.gemspec +3 -3
  5. data/README.md +1 -1
  6. data/lib/LittleWeasel/dictionary_key.rb +2 -2
  7. data/lib/LittleWeasel/dictionary_manager.rb +10 -4
  8. data/lib/LittleWeasel/metadata/metadatable.rb +5 -7
  9. data/lib/LittleWeasel/modules/dictionary_cache_validatable.rb +3 -5
  10. data/lib/LittleWeasel/modules/dictionary_key_validatable.rb +3 -5
  11. data/lib/LittleWeasel/modules/dictionary_metadata_validatable.rb +3 -5
  12. data/lib/LittleWeasel/modules/dictionary_source_validatable.rb +15 -0
  13. data/lib/LittleWeasel/modules/dictionary_sourceable.rb +66 -6
  14. data/lib/LittleWeasel/modules/dictionary_validatable.rb +0 -12
  15. data/lib/LittleWeasel/modules/language.rb +10 -9
  16. data/lib/LittleWeasel/modules/language_validatable.rb +2 -4
  17. data/lib/LittleWeasel/modules/locale.rb +7 -24
  18. data/lib/LittleWeasel/modules/order_validatable.rb +3 -5
  19. data/lib/LittleWeasel/modules/region.rb +10 -9
  20. data/lib/LittleWeasel/modules/region_validatable.rb +2 -4
  21. data/lib/LittleWeasel/modules/tag_validatable.rb +2 -4
  22. data/lib/LittleWeasel/preprocessors/preprocessed_word.rb +1 -0
  23. data/lib/LittleWeasel/preprocessors/preprocessed_word_validatable.rb +1 -0
  24. data/lib/LittleWeasel/preprocessors/preprocessed_words.rb +6 -2
  25. data/lib/LittleWeasel/preprocessors/preprocessed_words_validatable.rb +1 -0
  26. data/lib/LittleWeasel/preprocessors/word_preprocessor.rb +1 -0
  27. data/lib/LittleWeasel/services/dictionary_cache_service.rb +11 -62
  28. data/lib/LittleWeasel/services/dictionary_creator_service.rb +2 -2
  29. data/lib/LittleWeasel/services/dictionary_file_loader_service.rb +1 -1
  30. data/lib/LittleWeasel/services/dictionary_metadata_service.rb +4 -2
  31. data/lib/LittleWeasel/version.rb +1 -1
  32. data/spec/factories/dictionary_cache_service.rb +2 -2
  33. data/spec/lib/LittleWeasel/dictionary_manager_spec.rb +52 -2
  34. data/spec/lib/LittleWeasel/metadata/invalid_words_metadata_spec.rb +1 -1
  35. data/spec/lib/LittleWeasel/modules/dictionary_sourceable_spec.rb +56 -19
  36. data/spec/lib/LittleWeasel/modules/language_spec.rb +65 -5
  37. data/spec/lib/LittleWeasel/modules/locale_spec.rb +4 -49
  38. data/spec/lib/LittleWeasel/modules/region_spec.rb +65 -5
  39. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_managable_spec.rb +28 -2
  40. data/spec/lib/LittleWeasel/preprocessors/word_preprocessor_spec.rb +43 -0
  41. data/spec/lib/LittleWeasel/services/dictionary_cache_service_spec.rb +25 -25
  42. data/spec/support/file_helpers.rb +17 -3
  43. data/spec/support/shared_contexts.rb +0 -1
  44. metadata +12 -15
  45. data/lib/LittleWeasel/modules/dictionary_loader_servicable.rb +0 -27
  46. data/lib/LittleWeasel/services/dictionary_loader_service.rb +0 -59
  47. data/spec/factories/dictionary_loader_service.rb +0 -14
  48. data/spec/lib/LittleWeasel/services/dictionary_loader_service_spec.rb +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d55524bb27846962bd5cd9b83bf2b141c6f34ca723721630d980963be51f1e24
4
- data.tar.gz: 8f7efc3fb0db218dd6355f194b92352d12f901955c5388fe8f97e108cac7426b
3
+ metadata.gz: 96add6e70ce7b0619c3223931123d2ed9b438f7f294a2903053d2ba4a784af4b
4
+ data.tar.gz: bfe662b8c3a68295724139d68184f3413c7cad8193c491cae8737fadc29ea8ed
5
5
  SHA512:
6
- metadata.gz: 4027802eab13cb465e419dc8a95a6b3d6d905b6fffcc772bb33d485239fe2260bef778a0f33b526d5bc040dff59fb2c5cfb712b4a47cd4aa29e117c603fea886
7
- data.tar.gz: a54d138d51f8c66b42ff0a17880f6633370207223822dd6200766fd00fa70e6e19c4a29a9148183b586ed49f35eaf58d22b52d745059799f7147ec6a5c07a96d
6
+ metadata.gz: c8959e2b10b5bb97caac98b64046595ac676b120073f0e30d5f6ff2603bca09254ef0e7053af9c38f9ed940a14ae39a003c0453fafbcb6245cb2031e6bd22329
7
+ data.tar.gz: 02d671ece9011d096f17cfd61e9871c11e8536ef277cc147f77ab3f2ae6821e87c9edb255ab1d8981199ec9bdce9232be8c127db9bf12f30776d03ed8a1587b1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 5.0.0
2
+ * changes
3
+ * Add spec coverage where lacking.
4
+ * Remove unused DictionaryLoaderService and associated modules, specs, factories.
5
+ * Refactor Locale, Language and Region modules to simplify.
6
+ * Fix up DictionaryManager#dictionary_for which was published
7
+ half-baked in 4.0.0.
8
+ * DeprecateDictionaryCacheService#dictionary_exists? (plural); add typical DeprecateDictionaryCacheService#dictionary_exist? method in its palce.
9
+ * Update rake gem version to eliminate command injection vulerability.
10
+ * Change description and summary reflecting 4.0.0 changes.
11
+ * Various reek gem violation fixes/suppressions where reasonable.
12
+ * Fix most rubocop violations.
13
+
14
+ ### 4.0.0
15
+ * enhancements
16
+ * Complete overhaul; see README.md
17
+
1
18
  ### 3.0.4
2
19
  * enhancements
3
20
  * Relax requirements on ruby version to ~> 2.0.
@@ -13,4 +30,4 @@
13
30
  * None
14
31
 
15
32
  * bug fix
16
- * Calling #exists? no longer alters the original input.
33
+ * Calling #exists? no longer alters the original input.
data/Jenkinsfile ADDED
@@ -0,0 +1,20 @@
1
+ pipeline {
2
+ agent { docker { image 'ruby:3.0.1' } }
3
+ stages {
4
+ stage('requirements') {
5
+ steps {
6
+ sh 'gem install bundler -v 2.2.17'
7
+ }
8
+ }
9
+ stage('build') {
10
+ steps {
11
+ sh 'bundle install'
12
+ }
13
+ }
14
+ stage('test') {
15
+ steps {
16
+ sh 'bundle exec rspec'
17
+ }
18
+ }
19
+ }
20
+ }
data/LittleWeasel.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.version = LittleWeasel::VERSION
10
10
  spec.authors = ['Gene M. Angelo, Jr.']
11
11
  spec.email = ['public.gma@gmail.com']
12
- spec.description = 'Simple spellchecker for single, or multiple word blocks.'
13
- spec.summary = 'Simply checks a word or group of words for validity against an english dictionary file.'
12
+ spec.description = 'Spellchecker+ with preprocessing and filtering for single and multiple word blocks.'
13
+ spec.summary = 'Checks a word or group of words for validity against a dictionary/ies provided. Word filtering and word preprocessing is available.'
14
14
  spec.homepage = 'http://www.geneangelo.com'
15
15
  spec.license = 'MIT'
16
16
 
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'bundler', '~> 2.2', '>= 2.2.17'
26
26
  spec.add_development_dependency 'factory_bot', '~> 6.2'
27
27
  spec.add_development_dependency 'pry-byebug', '~> 3.9'
28
- spec.add_development_dependency 'rake', '~> 0'
28
+ spec.add_development_dependency 'rake', '>= 12.3.3'
29
29
  spec.add_development_dependency 'redcarpet', '~> 3.5', '>= 3.5.1'
30
30
  spec.add_development_dependency 'reek', '~> 6.0', '>= 6.0.4'
31
31
  spec.add_development_dependency 'rspec', '~> 3.10'
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![](http://ruby-gem-downloads-badge.herokuapp.com/LittleWeasel?type=total)](http://www.rubydoc.info/gems/LittleWeasel/)
5
5
  [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/LittleWeasel/)
6
6
 
7
- [![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/simple_command_dispatcher/issues)
7
+ [![Report Issues](https://img.shields.io/badge/report-issues-red.svg)](https://github.com/gangelo/LittleWeasel/issues)
8
8
 
9
9
  [![License](http://img.shields.io/badge/license-MIT-yellowgreen.svg)](#license)
10
10
 
@@ -19,10 +19,10 @@ module LittleWeasel
19
19
 
20
20
  def initialize(language:, region: nil, tag: nil)
21
21
  validate_language language: language
22
- self.language = self.class.normalize_language language
22
+ self.language = normalize_language language
23
23
 
24
24
  validate_region region: region
25
- self.region = self.class.normalize_region region
25
+ self.region = normalize_region region
26
26
 
27
27
  validate_tag tag: tag
28
28
  self.tag = tag
@@ -17,12 +17,18 @@ module LittleWeasel
17
17
  init
18
18
  end
19
19
 
20
- def dictionary_for(dictionary_key:)
20
+ # Returns true if a Dictionary object exists in the dictionary cache
21
+ # for the given dictionary_key.
22
+ def dictionary_exist?(dictionary_key:)
21
23
  validate_dictionary_key dictionary_key: dictionary_key
22
24
 
23
- unless dictionary_cache_service(dictionary_key: dictionary_key).dictionary_exists?
24
- # TODO: Raise an error or let the service handle it?
25
- end
25
+ dictionary_cache_service(dictionary_key: dictionary_key).dictionary_exist?
26
+ end
27
+
28
+ # Returns the Dictionary object associated with the dictionary_key. If the
29
+ # Dictionary object does not exist in the dictionary cache, an error is raised.
30
+ def dictionary_for(dictionary_key:)
31
+ validate_dictionary_key dictionary_key: dictionary_key
26
32
 
27
33
  dictionary_cache_service(dictionary_key: dictionary_key).dictionary_object!
28
34
  end
@@ -7,6 +7,8 @@ module LittleWeasel
7
7
  module Metadata
8
8
  # This module defines methods to support objects that manage other objects
9
9
  # that manage metadata related to a dictionary/ies.
10
+ # rubocop: disable Lint/UnusedMethodArgument, ignored - Methods in this
11
+ # module need to keep their argument names because of specs.
10
12
  module Metadatable
11
13
  def self.included(base)
12
14
  base.extend ClassMethods
@@ -52,12 +54,9 @@ module LittleWeasel
52
54
  # self.metadata = Services::InvalidWordsService.new(dictionary_words).execute
53
55
  # self
54
56
  # end
55
- #
56
- # rubocop: disable Lint/UnusedMethodArgument
57
57
  def init(params: nil)
58
58
  raise Errors::MustOverrideError
59
59
  end
60
- # rubocop: enable Lint/UnusedMethodArgument
61
60
 
62
61
  # This method should refresh the local metadata from the dictionary cache,
63
62
  # if metadata exists in the dictionary cache for the given metatata_key.
@@ -74,11 +73,9 @@ module LittleWeasel
74
73
  # init unless metadata.present?
75
74
  # self
76
75
  # end
77
- # rubocop: disable Lint/UnusedMethodArgument
78
76
  def refresh(params: nil)
79
77
  raise Errors::MustOverrideError
80
78
  end
81
- # rubocop: enable Lint/UnusedMethodArgument
82
79
 
83
80
  private
84
81
 
@@ -126,11 +123,12 @@ module LittleWeasel
126
123
  # dictionary_cache_service.dictionary_metadata_set(
127
124
  # metadata_key: metadata_key, value: value)
128
125
  # end
129
- # rubocop: disable Lint/UnusedMethodArgument
126
+ # :reek:UnusedParameters, ignored - This method is meant to be called with the given argument and raises an
127
+ # error if not overridden
130
128
  def update_dictionary_metadata(value:)
131
129
  raise Errors::MustOverrideError
132
130
  end
133
- # rubocop: enable Lint/UnusedMethodArgument
134
131
  end
132
+ # rubocop: enable Lint/UnusedMethodArgument
135
133
  end
136
134
  end
@@ -7,13 +7,11 @@ module LittleWeasel
7
7
  # related to one or more dictionaries. Dictionary cache objects are
8
8
  # normally specific to a DictionaryManager object.
9
9
  module DictionaryCacheValidatable
10
- def self.validate(dictionary_cache:)
11
- raise ArgumentError, "Argument dictionary_cache is not a valid Hash object: #{dictionary_cache.class}" \
12
- unless dictionary_cache.is_a? Hash
13
- end
10
+ module_function
14
11
 
15
12
  def validate_dictionary_cache(dictionary_cache:)
16
- DictionaryCacheValidatable.validate dictionary_cache: dictionary_cache
13
+ raise ArgumentError, "Argument dictionary_cache is not a valid Hash object: #{dictionary_cache.class}" \
14
+ unless dictionary_cache.is_a? Hash
17
15
  end
18
16
  end
19
17
  end
@@ -6,13 +6,11 @@ module LittleWeasel
6
6
  module Modules
7
7
  # Provides methods to validate a dictionary key object.
8
8
  module DictionaryKeyValidatable
9
- def self.validate(dictionary_key:)
10
- raise ArgumentError, "Argument dictionary_key is not a valid DictionaryKey object: #{dictionary_key.class}" \
11
- unless dictionary_key.is_a? DictionaryKey
12
- end
9
+ module_function
13
10
 
14
11
  def validate_dictionary_key(dictionary_key:)
15
- DictionaryKeyValidatable.validate(dictionary_key: dictionary_key)
12
+ raise ArgumentError, "Argument dictionary_key is not a valid DictionaryKey object: #{dictionary_key.class}" \
13
+ unless dictionary_key.is_a? DictionaryKey
16
14
  end
17
15
  end
18
16
  end
@@ -4,13 +4,11 @@ module LittleWeasel
4
4
  module Modules
5
5
  # This module provides methods to validate a dictionary metadata object.
6
6
  module DictionaryMetadataValidatable
7
- def self.validate(dictionary_metadata:)
8
- raise ArgumentError, "Argument dictionary_metadata is not a valid Hash object: #{dictionary_metadata.class}" \
9
- unless dictionary_metadata.is_a? Hash
10
- end
7
+ module_function
11
8
 
12
9
  def validate_dictionary_metadata(dictionary_metadata:)
13
- DictionaryMetadataValidatable.validate dictionary_metadata: dictionary_metadata
10
+ raise ArgumentError, "Argument dictionary_metadata is not a valid Hash object: #{dictionary_metadata.class}" \
11
+ unless dictionary_metadata.is_a? Hash
14
12
  end
15
13
  end
16
14
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LittleWeasel
4
+ module Modules
5
+ # This module provides methods to validate a dictionary source.
6
+ module DictionarySourceValidatable
7
+ module_function
8
+
9
+ def validate_dictionary_source(dictionary_source:)
10
+ raise ArgumentError, 'Argument dictionary_source is not present' \
11
+ unless dictionary_source.present?
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,26 +1,86 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'securerandom'
4
+ require_relative '../modules/dictionary_cache_keys'
5
+ require_relative '../modules/dictionary_source_validatable'
6
+ require_relative '../modules/dictionary_validatable'
4
7
 
5
8
  module LittleWeasel
6
9
  module Modules
7
10
  # This module provides methods to manage dictionary sources.
8
11
  module DictionarySourceable
9
- MEMORY_SOURCE = '*'
12
+ include Modules::DictionaryCacheKeys
13
+ include Modules::DictionarySourceValidatable
14
+ include Modules::DictionaryValidatable
10
15
 
11
- module_function
16
+ MEMORY_SOURCE = '*'
12
17
 
13
- def file_source?(source)
14
- !memory_source? source
18
+ def self.file_source?(dictionary_source)
19
+ !memory_source? dictionary_source
15
20
  end
16
21
 
17
- def memory_source?(source)
18
- source =~ /^#{Regexp.quote(MEMORY_SOURCE)}[0-9a-fA-F]{8}$/
22
+ def self.memory_source?(dictionary_source)
23
+ dictionary_source =~ /^#{Regexp.quote(MEMORY_SOURCE)}[0-9a-fA-F]{8}$/
19
24
  end
20
25
 
21
26
  def memory_source
22
27
  "#{MEMORY_SOURCE}#{SecureRandom.uuid[0..7]}"
23
28
  end
29
+ module_function :memory_source
30
+
31
+ # Adds a dictionary source. A "dictionary source" specifies the source from which
32
+ # the dictionary ultimately obtains its words.
33
+ #
34
+ # @param source [String] the dictionary source. This can be a file path
35
+ # or a memory source indicator to signify that the dictionary was created
36
+ # dynamically from memory.
37
+ def add_dictionary_source(dictionary_source:)
38
+ validate_dictionary_source_does_not_exist dictionary_cache_service: self
39
+
40
+ set_dictionary_reference \
41
+ dictionary_id: dictionary_id_associated_with(dictionary_source: dictionary_source)
42
+ # Only set the dictionary source if it doesn't already exist because settings
43
+ # the dictionary source wipes out the #dictionary_object; dictionary objects
44
+ # can have more than one dictionary reference pointing to them, and we don't
45
+ # want to blow away the #dictionary_object, metadata, or any other data
46
+ # associated with it if it already exists.
47
+ set_dictionary_source(dictionary_source: dictionary_source) unless dictionary?
48
+ self
49
+ end
50
+
51
+ def dictionary_source
52
+ dictionary_cache.dig(DICTIONARY_CACHE, DICTIONARIES, dictionary_id, SOURCE)
53
+ end
54
+ alias dictionary_file dictionary_source
55
+
56
+ def dictionary_source!
57
+ raise ArgumentError, "A dictionary source could not be found for key '#{key}'." \
58
+ unless dictionary_reference?
59
+
60
+ dictionary_cache[DICTIONARY_CACHE][DICTIONARIES][dictionary_id!][SOURCE]
61
+ end
62
+ alias dictionary_file! dictionary_source!
63
+
64
+ private
65
+
66
+ # Sets the dictionary source in the dictionary cache.
67
+ def set_dictionary_source(dictionary_source:)
68
+ dictionary_cache[DICTIONARY_CACHE][DICTIONARIES][dictionary_id!] = {
69
+ SOURCE => dictionary_source,
70
+ DICTIONARY_OBJECT => {}
71
+ }
72
+ end
73
+
74
+ # Returns the dictionary_id for the dictionary_source if it exists in
75
+ # dictionaries; otherwise, returns the new dictionary id that should
76
+ # be used.
77
+ def dictionary_id_associated_with(dictionary_source:)
78
+ dictionaries = dictionary_cache.dig(DICTIONARY_CACHE, DICTIONARIES)
79
+ dictionaries&.each_pair do |dictionary_id, dictionary_hash|
80
+ return dictionary_id if dictionary_source == dictionary_hash[SOURCE]
81
+ end
82
+ SecureRandom.uuid[0..7]
83
+ end
24
84
  end
25
85
  end
26
86
  end
@@ -13,18 +13,6 @@ module LittleWeasel
13
13
  raise "The dictionary source associated with key '#{dictionary_cache_service.key}' already exists."
14
14
  end
15
15
  end
16
-
17
- def validate_dictionary_does_not_exist(dictionary_cache_service:)
18
- if dictionary_cache_service.dictionary_exists?
19
- raise "The dictionary associated with key '#{dictionary_cache_service.key}' already exists."
20
- end
21
- end
22
-
23
- def validate_dictionary_reference_does_not_exist(dictionary_cache_service:)
24
- if dictionary_cache_service.dictionary_reference?
25
- raise "A dictionary reference associated with key '#{dictionary_cache_service.key}' already exists."
26
- end
27
- end
28
16
  end
29
17
  end
30
18
  end
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/object/blank'
4
+
3
5
  module LittleWeasel
4
6
  module Modules
5
7
  # Provides methods for normalizing language for a locale.
6
8
  module Language
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
+ def language?
10
+ language.present?
9
11
  end
10
12
 
11
- # class method inclusions for convenience.
12
- module ClassMethods
13
- def normalize_language(language)
14
- language&.downcase
15
- end
13
+ def normalize_language!
14
+ self.language = normalize_language language
16
15
  end
17
16
 
18
- def normalize_language
19
- self.class.normalize_language language
17
+ module_function
18
+
19
+ def normalize_language(language)
20
+ language&.downcase
20
21
  end
21
22
  end
22
23
  end
@@ -4,12 +4,10 @@ module LittleWeasel
4
4
  module Modules
5
5
  # This module provides methods to validate a language.
6
6
  module LanguageValidatable
7
- def self.validate(language:)
8
- raise ArgumentError, "Argument language '#{language}' is not a Symbol." unless language.is_a? Symbol
9
- end
7
+ module_function
10
8
 
11
9
  def validate_language(language:)
12
- LanguageValidatable.validate language: language
10
+ raise ArgumentError, "Argument language '#{language}' is not a Symbol." unless language.is_a? Symbol
13
11
  end
14
12
  end
15
13
  end
@@ -8,32 +8,15 @@ module LittleWeasel
8
8
  # This module provides methods to handle conversion of parts of a locale to
9
9
  # their string counter parts.
10
10
  module Locale
11
- def self.included(base)
12
- base.extend(ClassMethods)
13
- base.include(Language)
14
- base.include(Region)
15
- end
16
-
17
- # class method inclusions for convenience.
18
- module ClassMethods
19
- def locale(language:, region: nil)
20
- raise ArgumentError, 'Argument language does not respond to :downcase' unless language.respond_to? :downcase
21
-
22
- if region.present? && !region.respond_to?(:upcase)
23
- raise ArgumentError,
24
- 'Argument region does not respond to :upcase'
25
- end
26
-
27
- language = normalize_language language
28
- return language.to_s unless region.present?
29
-
30
- region = normalize_region region
31
- "#{language}-#{region}"
32
- end
33
- end
11
+ include Language
12
+ include Region
34
13
 
35
14
  def locale
36
- self.class.locale language: language, region: region
15
+ language = normalize_language self.language
16
+ return language.to_s unless region?
17
+
18
+ region = normalize_region self.region
19
+ "#{language}-#{region}"
37
20
  end
38
21
  end
39
22
  end
@@ -5,13 +5,11 @@ module LittleWeasel
5
5
  # This module provides methods to validate a value that can be used
6
6
  # in sorting.
7
7
  module OrderValidatable
8
- def self.validate(order:)
9
- raise ArgumentError, "Argument order is not an Integer: #{order.class}" unless order.is_a? Integer
10
- raise ArgumentError, "Argument order '#{order}' is not a a number from 0-n" if order.negative?
11
- end
8
+ module_function
12
9
 
13
10
  def validate_order(order:)
14
- OrderValidatable.validate order: order
11
+ raise ArgumentError, "Argument order is not an Integer: #{order.class}" unless order.is_a? Integer
12
+ raise ArgumentError, "Argument order '#{order}' is not a a number from 0-n" if order.negative?
15
13
  end
16
14
  end
17
15
  end
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/object/blank'
4
+
3
5
  module LittleWeasel
4
6
  module Modules
5
7
  # Provides methods for normalizing a region for a locale.
6
8
  module Region
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
+ def region?
10
+ region.present?
9
11
  end
10
12
 
11
- # class method inclusions for convenience.
12
- module ClassMethods
13
- def normalize_region(region)
14
- region&.upcase
15
- end
13
+ def normalize_region!
14
+ self.region = normalize_region region
16
15
  end
17
16
 
18
- def normalize_region
19
- self.class.normalize_region region
17
+ module_function
18
+
19
+ def normalize_region(region)
20
+ region&.upcase
20
21
  end
21
22
  end
22
23
  end
@@ -4,12 +4,10 @@ module LittleWeasel
4
4
  module Modules
5
5
  # This module provides methods to validate a region.
6
6
  module RegionValidatable
7
- def self.validate(region:)
8
- raise ArgumentError, "Argument region '#{region}' is not a Symbol." unless region.blank? || region.is_a?(Symbol)
9
- end
7
+ module_function
10
8
 
11
9
  def validate_region(region:)
12
- RegionValidatable.validate region: region
10
+ raise ArgumentError, "Argument region '#{region}' is not a Symbol." unless region.blank? || region.is_a?(Symbol)
13
11
  end
14
12
  end
15
13
  end
@@ -4,12 +4,10 @@ module LittleWeasel
4
4
  module Modules
5
5
  # This module provides methods to validate a tag.
6
6
  module TagValidatable
7
- def self.validate(tag:)
8
- raise ArgumentError, "Argument tag '#{tag}' is not a Symbol." unless tag.blank? || tag.is_a?(Symbol)
9
- end
7
+ module_function
10
8
 
11
9
  def validate_tag(tag:)
12
- TagValidatable.validate tag: tag
10
+ raise ArgumentError, "Argument tag '#{tag}' is not a Symbol." unless tag.blank? || tag.is_a?(Symbol)
13
11
  end
14
12
  end
15
13
  end
@@ -7,6 +7,7 @@ module LittleWeasel
7
7
  # are used to preprocess a word before it is passed to any
8
8
  # Filters::WordFilters, and before it is compared against the
9
9
  # dictionary for validity.
10
+ # :reek:Attribute, ignored - Fixing this would result in nothing but trivial setter methods
10
11
  class PreprocessedWord
11
12
  attr_accessor :original_word, :preprocessed, :preprocessed_word, :preprocessor, :preprocessor_order
12
13
 
@@ -4,6 +4,7 @@ module LittleWeasel
4
4
  module Preprocessors
5
5
  # This module provides functionality that validates preprocessed word types.
6
6
  # rubocop: disable Layout/LineLength
7
+ # :reek:ManualDispatch, ignored - these methods are raising errors, not performing conditional code execution
7
8
  module PreprocessedWordValidatable
8
9
  module_function
9
10
 
@@ -5,8 +5,7 @@ module LittleWeasel
5
5
  # This class provides a container for Preprocessors::PreprocessedWord
6
6
  # objects.
7
7
  class PreprocessedWords
8
- attr_reader :original_word
9
- attr_accessor :preprocessed_words
8
+ attr_reader :original_word, :preprocessed_words
10
9
 
11
10
  # original_word:String the unsullied word before any preprocessing has
12
11
  # been applied to it.
@@ -38,6 +37,11 @@ module LittleWeasel
38
37
  end
39
38
  end
40
39
 
40
+ def preprocessed_words=(value)
41
+ value ||= []
42
+ @preprocessed_words = value
43
+ end
44
+
41
45
  def preprocessed_word
42
46
  self.class.preprocessed_word preprocessed_words: preprocessed_words
43
47
  end
@@ -9,6 +9,7 @@ module LittleWeasel
9
9
  module PreprocessedWordsValidatable
10
10
  module_function
11
11
 
12
+ # :reek:ManualDispatch, ignored - this is raising an error, not conditional code execution
12
13
  def validate_prepreprocessed_words(preprocessed_words:)
13
14
  raise ArgumentError, validation_error_message(object: preprocessed_words, respond_to: :original_word) unless preprocessed_words.respond_to? :original_word
14
15
  raise ArgumentError, validation_error_message(object: preprocessed_words, respond_to: :preprocessed_words) unless preprocessed_words.respond_to? :preprocessed_words
@@ -11,6 +11,7 @@ module LittleWeasel
11
11
  # word preprocessors. A "word preprocessor" is an object that manipulates a
12
12
  # word before it is passed to any word filters and before it is compared
13
13
  # against the dictionary for validity.
14
+ # :reek:MissingSafeMethod, ignored - safe methods for preprocessor_on!/off! make no sense in this case
14
15
  class WordPreprocessor
15
16
  include Modules::ClassNameToSymbol
16
17
  include Modules::Orderable