diff --git a/lib/rambling/trie.rb b/lib/rambling/trie.rb index 04c8fe23..e3b84a0c 100644 --- a/lib/rambling/trie.rb +++ b/lib/rambling/trie.rb @@ -26,7 +26,7 @@ def create filepath = nil, reader = nil if filepath reader ||= readers.resolve filepath # noinspection RubyMismatchedArgumentType,RubyNilAnalysis - reader.each_word filepath do |word| + (reader || raise).each_word filepath do |word| container << word end end @@ -48,7 +48,7 @@ def create filepath = nil, reader = nil # discouraged. Only use the +.marshal+ format with trusted input. def load filepath, serializer = nil serializer ||= serializers.resolve filepath - root = serializer.load filepath + root = (serializer || raise).load filepath Rambling::Trie::Container.new root, compressor do |container| yield container if block_given? end @@ -66,7 +66,7 @@ def load filepath, serializer = nil def dump trie, filepath, serializer = nil serializer ||= serializers.resolve filepath # noinspection RubyNilAnalysis - serializer.dump trie.root, filepath + (serializer || raise).dump trie.root, filepath end # Provides configuration properties for the +Rambling::Trie+ gem. diff --git a/lib/rambling/trie/configuration/provider_collection.rb b/lib/rambling/trie/configuration/provider_collection.rb index 7e827433..059467e4 100644 --- a/lib/rambling/trie/configuration/provider_collection.rb +++ b/lib/rambling/trie/configuration/provider_collection.rb @@ -104,7 +104,9 @@ def file_format filepath end def contains? provider - provider.nil? || (providers.any? && provider_instances.include?(provider)) + return true if provider.nil? + p = (provider || raise) + providers.any? && provider_instances.include?(p) end alias_method :provider_instances, :values diff --git a/lib/rambling/trie/nodes/compressed.rb b/lib/rambling/trie/nodes/compressed.rb index eecc4041..d9fcc8ce 100644 --- a/lib/rambling/trie/nodes/compressed.rb +++ b/lib/rambling/trie/nodes/compressed.rb @@ -23,13 +23,13 @@ def compressed? private def partial_word_chars? chars - child = children_tree[chars.first.to_sym] + child = children_tree[(chars.first || raise).to_sym] return false unless child child_letter = child.letter.to_s if chars.size >= child_letter.size - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join return child.partial_word? chars if child_letter == letter end @@ -39,7 +39,7 @@ def partial_word_chars? chars end def word_chars? chars - letter = chars.slice! 0 + letter = chars.slice!(0) || raise letter_sym = letter.to_sym child = children_tree[letter_sym] @@ -50,7 +50,7 @@ def word_chars? chars break if chars.empty? - letter << chars.slice!(0) + letter << (chars.slice!(0) || raise) letter_sym = letter.to_sym end @@ -58,13 +58,13 @@ def word_chars? chars end def closest_node chars - child = children_tree[chars.first.to_sym] + child = children_tree[(chars.first || raise).to_sym] return missing unless child child_letter = child.letter.to_s if chars.size >= child_letter.size - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join return child.scan chars if child_letter == letter end @@ -79,11 +79,11 @@ def children_match_prefix chars return EMPTY_ENUMERATOR if chars.empty? - child = children_tree[chars.first.to_sym] + child = children_tree[(chars.first || raise).to_sym] return EMPTY_ENUMERATOR unless child child_letter = child.letter.to_s - letter = chars.slice!(0, child_letter.size).join + letter = (chars.slice!(0, child_letter.size) || raise).join return EMPTY_ENUMERATOR unless child_letter == letter diff --git a/lib/rambling/trie/nodes/raw.rb b/lib/rambling/trie/nodes/raw.rb index 1fefacad..1c3558d3 100644 --- a/lib/rambling/trie/nodes/raw.rb +++ b/lib/rambling/trie/nodes/raw.rb @@ -27,7 +27,7 @@ def compressed? private def add_to_children_tree chars - letter = chars.pop + letter = chars.pop || raise child = children_tree[letter] || new_node(letter) child.add chars child @@ -40,7 +40,7 @@ def new_node letter end def partial_word_chars? chars = [] - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return false unless child @@ -48,7 +48,7 @@ def partial_word_chars? chars = [] end def word_chars? chars = [] - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return false unless child @@ -56,7 +56,7 @@ def word_chars? chars = [] end def closest_node chars - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return missing unless child @@ -68,7 +68,7 @@ def children_match_prefix chars return EMPTY_ENUMERATOR if chars.empty? - letter = chars.shift.to_sym + letter = (chars.shift || raise).to_sym child = children_tree[letter] return EMPTY_ENUMERATOR unless child diff --git a/lib/rambling/trie/serializers/zip.rb b/lib/rambling/trie/serializers/zip.rb index 809fbc9f..740b63b9 100644 --- a/lib/rambling/trie/serializers/zip.rb +++ b/lib/rambling/trie/serializers/zip.rb @@ -26,12 +26,14 @@ def load filepath ::Zip::File.open filepath do |zip| entry = zip.entries.first - return nil if entry.nil? + raise if entry.nil? entry_path = path entry.name entry.extract entry_path serializer = serializers.resolve entry.name + raise if serializer.nil? + serializer.load entry_path end end @@ -50,6 +52,8 @@ def dump contents, filepath entry_path = path filename serializer = serializers.resolve filename + + raise if serializer.nil? serializer.dump contents, entry_path zip.add filename, entry_path