mongoid-giza 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d368cbce54de65a25b4965b2e25ee101f4fd0a99
4
- data.tar.gz: cdb575b3810acb882ca135583cb3c2231d4d068d
3
+ metadata.gz: e68c24c85a8ab1a5058c90204c1b4b48c8894717
4
+ data.tar.gz: 23a10d3f8db970eef859cb5b4675f15c42cdf4c7
5
5
  SHA512:
6
- metadata.gz: 66ec17363af5ff16a8563c9f797ddff95ec63b93794c6170e5b0cd487d1aeb208d983e9f4ca811eeeb0d68e986088a9bd74eb3a7245f5c346f54b202278b6c15
7
- data.tar.gz: 8c8178f9cbe3b638da95b0712b1ffb08283b97ef1f2af6bcaa47b746cafc28ef84fb47de09da8edf0a08f7c1c6bdaf0a1a3d8defd2cbe456ee95ce38b630fe89
6
+ metadata.gz: 7ebbc8f78cae69b1eac182a59ceadbc9b1b3c6c43f968e190d75078a812fb939df5967ba59740df6ae6304ac12eb65f2332a8d308587d4b48fe820ccef609f8f
7
+ data.tar.gz: 08c98fb01da3de22b160cbebe2c8a7c69eee0124e26cfc2f5d8078d6e41f324cce8e52660c2644391570fd9742ca0195b6ca801d7b801145754608fb704bcfc9
@@ -0,0 +1,10 @@
1
+ Style/SpaceInsideHashLiteralBraces:
2
+ EnforcedStyle: no_space
3
+
4
+ Style/Encoding:
5
+ Enabled: true
6
+ EnforcedStyle: when_needed
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+
@@ -3,5 +3,6 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.1
6
+ - 2.2.1
6
7
  services:
7
8
  - mongodb
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ * Mongoid 4 or higher is now required
6
+ * Removed charset_type option, since it has been removed from spinx since 2.2.2-beta. You can still define it in your confuguration if you're using an older sphinx version
7
+ * Renamed `Mongoid::Giza::GizaID` to `Mongoid::Giza::ID`
8
+ * Renamed `Mongoid::Giza::ID::next_id to Mongoid::Giza::ID::next`
9
+ * Renamed `giza_id` to `_giza_id`. Now it's a regular field instead of being dynamically assigned when needed
10
+ * Support for `default` and `bits` for attributes
11
+ * Removed *str2ordinal* and *str2wordcount* attribute types
12
+ * Automatically convert Date, Time and DateTime attributes to unix time
13
+ * Only support **ONE** fulltext query by *search block*. Instead of returning an Array o result Hashes now it only returns a result Hash
14
+
3
15
  ## 0.5.1
4
16
 
5
17
  * Create a sparse unique index on `giza_id` field
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'coveralls', require: false
3
+ gem "coveralls", require: false
4
4
 
5
5
  # Specify your gem's dependencies in mongoid-giza.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -168,7 +168,6 @@ Use the `search` block on the class that have the indexes where the search shoul
168
168
  It returns a result array, where each position of the array is a [riddle result hash](http://rdoc.info/github/pat/riddle/Riddle/Client#query-instance_method), plus a key with the class name, that has the `Mongoid::Criteria` that selects the matching objects from the mongo database.
169
169
 
170
170
  Inside the `search` block use the `fulltext` method to perform a fulltext search.
171
- If multiple `fulltext` are called inside a `search` block, then each one will generate a separated query and will return a new position o the results array.
172
171
 
173
172
  To filter your search using the attributes defined on the index creation, use the `with` and `without` methods, that accept the name of the attribute and the value or range.
174
173
 
@@ -179,13 +178,13 @@ Every other [Riddle::Client](http://rdoc.info/github/pat/riddle/Riddle/Client) s
179
178
  **Example:** Searching on the person class
180
179
 
181
180
  ```ruby
182
- results = Person.search do
181
+ result = Person.search do
183
182
  fulltext "john"
184
183
  with :age 18..40
185
184
  order_by :age :asc
186
185
  end
187
186
 
188
- results.first[:Person].each do |person|
187
+ result[:Person].each do |person|
189
188
  puts "#{person.name} is #{person.age} years old"
190
189
  end
191
190
  ```
data/Rakefile CHANGED
@@ -3,9 +3,17 @@ Bundler.setup
3
3
 
4
4
  require "bundler/gem_tasks"
5
5
  require "rspec/core/rake_task"
6
+ require "rubocop/rake_task"
6
7
 
7
- RSpec::Core::RakeTask.new("spec") do |spec|
8
+ RuboCop::RakeTask.new(:rubocop)
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
11
  spec.pattern = "spec/**/*_spec.rb"
9
12
  end
10
13
 
11
- task default: :spec
14
+ task :build do
15
+ Rake::Task[:rubocop].invoke
16
+ Rake::Task[:spec].invoke
17
+ end
18
+
19
+ task default: :build
@@ -7,18 +7,18 @@ require "mongoid/giza/index"
7
7
  require "mongoid/giza/index/field"
8
8
  require "mongoid/giza/index/attribute"
9
9
  require "mongoid/giza/indexer"
10
- require "mongoid/giza/models/giza_id"
10
+ require "mongoid/giza/models/id"
11
11
  require "mongoid/giza/railtie" if defined?(Rails)
12
12
  require "mongoid/giza/search"
13
13
  require "mongoid/giza/version"
14
14
  require "mongoid/giza/xml_pipe2"
15
15
 
16
16
  module Mongoid
17
-
18
17
  # Module that should be included in a Mongoid::Document in order to
19
- # index fields of documents of this class
18
+ # index fields of documents of this class
20
19
  #
21
- # @example Creating a simple index with a full-text field (named fts) and an attribute (named attr)
20
+ # @example Creating a simple index with a full-text field (named fts) and an
21
+ # attribute (named attr)
22
22
  # class Person
23
23
  # include Mongoid::Document
24
24
  # include Mongoid::Giza
@@ -32,7 +32,8 @@ module Mongoid
32
32
  # end
33
33
  # end
34
34
  #
35
- # @example Searching the previously defined index for people named John between 18 and 59 years old
35
+ # @example Searching the previously defined index for people named John
36
+ # between 18 and 59 years old
36
37
  # results = Person.search do
37
38
  # fulltext "john"
38
39
  # with age: 18..59
@@ -43,57 +44,56 @@ module Mongoid
43
44
  extend ActiveSupport::Concern
44
45
 
45
46
  included do
46
- Mongoid::Giza::GizaID.create(id: name.to_sym)
47
- index({giza_id: 1}, {sparse: true, unique: true})
47
+ ID.create(id: name.to_sym) unless ID.where(id: name.to_sym).count == 1
48
+ field :_giza_id, type: Integer,
49
+ default: -> { ID.next(self.class.name.to_sym) }
50
+ index({_giza_id: 1}, sparse: true, unique: true)
48
51
  @giza_configuration = Configuration.instance
49
52
  @static_sphinx_indexes = {}
50
53
  @generated_sphinx_indexes = {}
51
54
  @dynamic_sphinx_indexes = []
52
55
  end
53
56
 
54
- # Retrives the sphinx compatible id of the object.
55
- # If the id does not exists yet, it will be generated
56
- #
57
- # @return [Integer] the object's integer id generated by Giza
58
- def giza_id
59
- set(:giza_id, GizaID.next_id(self.class.name.to_sym)) if self[:giza_id].nil?
60
- self[:giza_id]
61
- end
62
-
63
57
  # Generates all the dynamic indexes defined on the class for the object
64
58
  def generate_sphinx_indexes
65
59
  self.class.dynamic_sphinx_indexes.each do |dynamic_index|
66
60
  index = dynamic_index.generate_index(self)
67
- self.class.generated_sphinx_indexes.merge!({index.name => index})
61
+ self.class.generated_sphinx_indexes.merge!(index.name => index)
68
62
  self.class.giza_configuration.add_index(index, true)
69
63
  end
70
64
  end
71
65
 
66
+ # :nodoc:
72
67
  module ClassMethods
73
- attr_reader :giza_configuration, :static_sphinx_indexes, :generated_sphinx_indexes, :dynamic_sphinx_indexes
68
+ attr_reader :giza_configuration, :static_sphinx_indexes,
69
+ :generated_sphinx_indexes, :dynamic_sphinx_indexes
74
70
 
75
- # Class method that defines a index relative to the current class' objects.
76
- # If an argument is given in the block then a dynamic index will be created.
71
+ # Class method that defines a index relative to the current class objects.
72
+ # If an argument is given in the block then a dynamic index will be
73
+ # created.
77
74
  # Otherwise it will create a static index.
78
75
  #
79
76
  # @param settings [Hash] optional settings for the index and it's source
80
- # @param block [Proc] a block that will be evaluated on an {Mongoid::Giza::Index}
77
+ # @param block [Proc] a block that will be evaluated on an
78
+ # {Mongoid::Giza::Index}
81
79
  def sphinx_index(settings = {}, &block)
82
- if block_given?
83
- if block.arity > 0
84
- add_dynamic_sphinx_index(settings, block)
85
- else
86
- add_static_sphinx_index(settings, block)
87
- end
80
+ return unless block_given?
81
+ if block.arity > 0
82
+ add_dynamic_sphinx_index(settings, block)
83
+ else
84
+ add_static_sphinx_index(settings, block)
88
85
  end
89
86
  end
90
87
 
91
88
  # Adds an dynamic index to the class.
92
- # Will also automatically generate the dynamic index for each object of the class
89
+ # Will also automatically generate the dynamic index for each object of
90
+ # the class
93
91
  #
94
92
  # @param settings [Hash] settings for the index and it's source
95
- # @param block [Proc] a block that will be evaluated on an {Mongoid::Giza::Index}.
96
- # The block receives one argument that is the current object of the class for which the index will be generated
93
+ # @param block [Proc] a block that will be evaluated on an
94
+ # {Mongoid::Giza::Index}.
95
+ # The block receives one argument that is the current object of the
96
+ # class for which the index will be generated
97
97
  def add_dynamic_sphinx_index(settings, block)
98
98
  dynamic_index = DynamicIndex.new(self, settings, block)
99
99
  dynamic_sphinx_indexes << dynamic_index
@@ -103,7 +103,8 @@ module Mongoid
103
103
  # Adds an static index to the class
104
104
  #
105
105
  # @param settings [Hash] settings for the index and it's source
106
- # @param block [Proc] a block that will be evaluated on an {Mongoid::Giza::Index}.
106
+ # @param block [Proc] a block that will be evaluated on an
107
+ # {Mongoid::Giza::Index}.
107
108
  def add_static_sphinx_index(settings, block)
108
109
  index = Index.new(self, settings)
109
110
  Docile.dsl_eval(index, &block)
@@ -114,66 +115,104 @@ module Mongoid
114
115
  # Generates the indexes from the dynamic index and
115
116
  # registers them on the class and on the configuration
116
117
  #
117
- # @param dynamic_index [Mongoid::Giza::DynamicIndex] the dynamic index which will generate the static indexes from
118
+ # @param dynamic_index [Mongoid::Giza::DynamicIndex] the dynamic index
119
+ # which will generate the static indexes from
118
120
  def process_dynamic_sphinx_index(dynamic_index)
119
121
  generated = dynamic_index.generate!
120
122
  generated_sphinx_indexes.merge!(generated)
121
- generated.each { |name, index| giza_configuration.add_index(index, true) }
123
+ generated.each { |_, index| giza_configuration.add_index(index, true) }
122
124
  end
123
125
 
124
- # Class method that implements a search DSL using a {Mongoid::Giza::Search} object.
125
- # The search will run on indexes defined on the class unless it's overwritten using {Mongoid::Giza::Search#indexes=}
126
+ # Class method that implements a search DSL using a
127
+ # {Mongoid::Giza::Search} object.
128
+ # The search will run on indexes defined on the class unless it's
129
+ # overwritten using {Mongoid::Giza::Search#indexes=}
126
130
  #
127
- # @param block [Proc] a block that will be evaluated on a {Mongoid::Giza::Search}
131
+ # @param block [Proc] a block that will be evaluated on a
132
+ # {Mongoid::Giza::Search}
128
133
  #
129
- # @return [Array] an Array with Riddle result hashes containing an additional key with the name of the class.
130
- # The value of this aditional key is a Mongoid::Criteria that return the actual objects of the match
134
+ # @return [Hash] a Riddle result Hash containing an
135
+ # additional key with the name of the class.
136
+ # The value of this aditional key is a Mongoid::Criteria that return the
137
+ # actual objects of the match
131
138
  def search(&block)
132
- search = Mongoid::Giza::Search.new(giza_configuration.searchd.address, giza_configuration.searchd.port, sphinx_indexes_names)
139
+ search = Search.new(giza_configuration.searchd.address,
140
+ giza_configuration.searchd.port,
141
+ sphinx_indexes_names)
133
142
  Docile.dsl_eval(search, &block)
134
- results = search.run
135
- results.each { |result| result[name.to_sym] = self.in(giza_id: result[:matches].map { |match| match[:doc] }) }
143
+ map_to_mongoid(search.run)
136
144
  end
137
145
 
138
146
  # Regenerates all dynamic indexes of the class
139
147
  def regenerate_sphinx_indexes
140
- giza_configuration.remove_generated_indexes(generated_sphinx_indexes.keys)
148
+ giza_configuration
149
+ .remove_generated_indexes(generated_sphinx_indexes.keys)
141
150
  generated_sphinx_indexes.clear
142
- dynamic_sphinx_indexes.each { |dynamic_index| process_dynamic_sphinx_index(dynamic_index) }
151
+ dynamic_sphinx_indexes.each do |dynamic_index|
152
+ process_dynamic_sphinx_index(dynamic_index)
153
+ end
143
154
  end
144
155
 
145
156
  # Removes the generated indexes.
146
157
  #
147
- # @param names [Array] a list of generated index names that should be removed
158
+ # @param names [Array] a list of generated index names that should be
159
+ # removed
148
160
  def remove_generated_sphinx_indexes(*names)
149
161
  names.each { |name| generated_sphinx_indexes.delete(name) }
150
162
  giza_configuration.remove_generated_indexes(names)
151
163
  end
152
164
 
153
165
  # Execute the indexing routines of the indexes defined on the class.
154
- # This means (re)create the sphinx configuration file and then execute the indexer program on it.
155
- # If no index names are supplied than all indexes defined on the class will be indexed.
156
- # If none of the index names supplied are on this class then nothing is indexed
166
+ # This means (re)create the sphinx configuration file and then execute the
167
+ # indexer program on it.
168
+ # If no index names are supplied than all indexes defined on the class
169
+ # will be indexed.
170
+ # If none of the index names supplied are on this class then nothing is
171
+ # indexed
157
172
  #
158
- # @param names [Array] a list of index names of this class that will be indexed
173
+ # @param names [Array] a list of index names of this class that will be
174
+ # indexed
159
175
  def sphinx_indexer!(*names)
160
- indexes_names = names.length > 0 ? sphinx_indexes_names.select { |name| names.include? name } : sphinx_indexes_names
161
- Mongoid::Giza::Indexer.instance.index!(*indexes_names) if indexes_names.length > 0
176
+ if names.length > 0
177
+ indexes_names =
178
+ sphinx_indexes_names.select { |name| names.include?(name) }
179
+ else
180
+ indexes_names = sphinx_indexes_names
181
+ end
182
+ Indexer.instance.index!(*indexes_names) if indexes_names.length > 0
162
183
  end
163
184
 
164
- # Retrieves all the sphinx indexes defined on this class, static and dynamic
185
+ # Retrieves all the sphinx indexes defined on this class, static and
186
+ # dynamic
165
187
  #
166
- # @return [Hash] a Hash with indexes names as keys and the actual indexes as the values
188
+ # @return [Hash] a Hash with indexes names as keys and the actual indexes
189
+ # as the values
167
190
  def sphinx_indexes
168
191
  static_sphinx_indexes.merge(generated_sphinx_indexes)
169
192
  end
170
193
 
171
- # Retrieves all the names of sphinx indexes defined on this class, static and dynamic
194
+ # Retrieves all the names of sphinx indexes defined on this class, static
195
+ # and dynamic
172
196
  #
173
- # @return [Array] an Array of names of indexes from the current class {Mongoid::Giza::Index}
197
+ # @return [Array] an Array of names of indexes from the current class
198
+ # {Mongoid::Giza::Index}
174
199
  def sphinx_indexes_names
175
200
  static_sphinx_indexes.merge(generated_sphinx_indexes).keys
176
201
  end
202
+
203
+ private
204
+
205
+ # Creates the Mongoid::Criteria that return the objects matched by the
206
+ # sphinx search
207
+ #
208
+ # @param result [Hash] the query result created by Riddle
209
+ # @return [Hash] the result hash with the Mongoid::Criteria on the indexed
210
+ # class' name key
211
+ def map_to_mongoid(result)
212
+ result[name.to_sym] =
213
+ self.in(_giza_id: result[:matches].map { |match| match[:doc] })
214
+ result
215
+ end
177
216
  end
178
217
  end
179
218
  end
@@ -4,7 +4,6 @@ require "yaml"
4
4
 
5
5
  module Mongoid
6
6
  module Giza
7
-
8
7
  # Holds the configuration of the module
9
8
  class Configuration < Riddle::Configuration
10
9
  include Singleton
@@ -24,16 +23,18 @@ module Mongoid
24
23
  # Loads a YAML file with settings defined.
25
24
  # Settings that are not recognized are ignored
26
25
  #
27
- # @param path [String] path to the YAML file which contains the settings defined
26
+ # @param path [String] path to the YAML file which contains the settings
27
+ # defined
28
28
  # @param env [String] environment whoose settings will be loaded
29
29
  def load(path, env)
30
30
  YAML.load(File.open(path).read)[env].each do |section_name, settings|
31
31
  section = instance_variable_get("@#{section_name}")
32
- if !section.nil?
33
- settings.each do |setting, value|
34
- value = interpolate_string(value, nil) if section != @index and section != @source
35
- setter(section, setting, value)
32
+ next unless section
33
+ settings.each do |setting, value|
34
+ unless section == @index || section == @source
35
+ value = interpolate_string(value, nil)
36
36
  end
37
+ setter(section, setting, value)
37
38
  end
38
39
  end
39
40
  end
@@ -41,21 +42,21 @@ module Mongoid
41
42
  # Adds an index to the sphinx configuration,
42
43
  # so this index can be rendered on the configuration file
43
44
  #
44
- # @param index [Mongoid::Giza::Index] the index that will be added to the configuration
45
- # @param generated [TrueClass, FalseClass] determines if this index was generated from a {Mongoid::Giza::DynamicIndex}
45
+ # @param index [Mongoid::Giza::Index] the index that will be added to the
46
+ # configuration
47
+ # @param generated [TrueClass, FalseClass] determines if this index was
48
+ # generated from a {Mongoid::Giza::DynamicIndex}
46
49
  def add_index(index, generated = false)
47
50
  riddle_index = create_index(index)
48
- if generated
49
- position = register_index(riddle_index, @generated_indexes)
50
- else
51
- position = register_index(riddle_index, @static_indexes)
52
- end
51
+ indexes = generated ? @generated_indexes : @static_indexes
52
+ position = register_index(riddle_index, indexes)
53
53
  indices[position] = riddle_index
54
54
  end
55
55
 
56
56
  # Creates a new Riddle::Index based on the given {Mongoid::Giza::Index}
57
57
  #
58
- # @param index [Mongoid::Giza::Index] the index to generate the configuration from
58
+ # @param index [Mongoid::Giza::Index] the index to generate the
59
+ # configuration from
59
60
  #
60
61
  # @return [Riddle::Configuration::Index] the created riddle index
61
62
  def create_index(index)
@@ -66,39 +67,51 @@ module Mongoid
66
67
  apply_user_settings(index, riddle_index)
67
68
  apply_user_settings(index, source)
68
69
  riddle_index.path = File.join(riddle_index.path, index.name.to_s)
69
- riddle_index.charset_type = "utf-8"
70
70
  riddle_index
71
71
  end
72
72
 
73
73
  # Adds the riddle index to it's respective collection
74
74
  #
75
- # @param index [Riddle::Configuration::Index] the index that will be registrated
75
+ # @param riddle_index [Riddle::Configuration::Index] the index that will
76
+ # be registrated
76
77
  # @param indexes [Hash] the collection which will hold this index
77
78
  #
78
- # @return [Integer] the position where this index should be inserted on the configuration indices array
79
- def register_index(index, indexes)
80
- position = indexes.has_key?(index.name) ? indices.index(indexes[index.name]) : indices.length
81
- indexes[index.name] = index
79
+ # @return [Integer] the position where this index should be inserted on
80
+ # the configuration indices array
81
+ def register_index(riddle_index, indexes)
82
+ position = indices.index(indexes[riddle_index.name]) || indices.length
83
+ indexes[riddle_index.name] = riddle_index
82
84
  position
83
85
  end
84
86
 
85
- # Applies the settings defined on an object loaded from the configuration to a Riddle::Configuration::Index or Riddle::Configuration::XMLSource instance.
86
- # Used internally by {#add_index} so you should never need to call it directly
87
+ # Applies the settings defined on an object loaded from the configuration
88
+ # to a Riddle::Configuration::Index or Riddle::Configuration::XMLSource
89
+ # instance.
90
+ # Used internally by {#add_index} so you should never need to call it
91
+ # directly
87
92
  #
88
- # @param default [Riddle::Configuration::Index, Riddle::Configuration::XMLSource] the object that holds the global settings values
89
- # @param section [Riddle::Configuration::Index, Riddle::Configuration::XMLSource] the object that settings are being set
93
+ # @param default [Riddle::Configuration::Index,
94
+ # Riddle::Configuration::XMLSource] the object that holds the global
95
+ # settings values
96
+ # @param section [Riddle::Configuration::Index,
97
+ # Riddle::Configuration::XMLSource] the object that settings are being
98
+ # set
90
99
  def apply_default_settings(default, section, index)
91
100
  default.class.settings.each do |setting|
92
101
  value = interpolate_string(default.send("#{setting}"), index)
93
- setter(section, setting, value) if !value.nil?
102
+ setter(section, setting, value) unless value.nil?
94
103
  end
95
104
  end
96
105
 
97
- # Applies the settings defined on a {Mongoid::Giza::Index} to the Riddle::Configuration::Index or Riddle::Configuration::XMLSource.
98
- # Used internally by {#add_index} so you should never need to call it directly
106
+ # Applies the settings defined on a {Mongoid::Giza::Index} to the
107
+ # Riddle::Configuration::Index or Riddle::Configuration::XMLSource.
108
+ # Used internally by {#add_index} so you should never need to call it
109
+ # directly
99
110
  #
100
- # @param index [Mongoid::Giza::Index] the index where the settings were defined
101
- # @param section [Riddle::Configuration::Index, Riddle::Configuration::XMLSource] where the settings will be applied
111
+ # @param index [Mongoid::Giza::Index] the index where the settings were
112
+ # defined
113
+ # @param section [Riddle::Configuration::Index,
114
+ # Riddle::Configuration::XMLSource] where the settings will be applied
102
115
  def apply_user_settings(index, section)
103
116
  index.settings.each do |setting, value|
104
117
  value = interpolate_string(value, index)
@@ -111,15 +124,17 @@ module Mongoid
111
124
  File.open(@file.output_path, "w") { |file| file.write(super) }
112
125
  end
113
126
 
114
- # Removes all Riddle::Index from the indices Array that were created from a generated {Mongoid::Giza::Index}
127
+ # Removes all Riddle::Index from the indices Array that were created from
128
+ # a generated {Mongoid::Giza::Index}
115
129
  def clear_generated_indexes
116
- @generated_indexes.each { |name, index| indices.delete(index) }
130
+ @generated_indexes.each { |_, index| indices.delete(index) }
117
131
  @generated_indexes = {}
118
132
  end
119
133
 
120
134
  # Removes Riddle::Index's specifieds as params
121
135
  #
122
- # @param names [Array<Symbol>] names of generated indexes that should be removed
136
+ # @param names [Array<Symbol>] names of generated indexes that should be
137
+ # removed
123
138
  def remove_generated_indexes(names)
124
139
  names.each do |name|
125
140
  indices.delete(@generated_indexes.delete(name))
@@ -128,22 +143,31 @@ module Mongoid
128
143
 
129
144
  # Interpolates a value if it's a String using ERB.
130
145
  # Useful for defining dynamic settings.
131
- # The ERB template may reference to the current {Mongoid::Giza::Index} and it's methods
146
+ # The ERB template may reference to the current {Mongoid::Giza::Index} and
147
+ # it's methods
132
148
  #
133
149
  # @param value [String] the ERB template that will be interpolated
134
- # @param index [Mongoid::Giza::Index] the index that will be accessible from the template
150
+ # @param index [Mongoid::Giza::Index] the index that will be accessible
151
+ # from the template
135
152
  #
136
- # @return [Object] if value was a String and contains ERB syntax than it will beinterpolated and returned.
153
+ # @return [Object] if value was a String and contains ERB syntax than it
154
+ # will beinterpolated and returned.
137
155
  # Otherwise it will return the original value
138
156
  def interpolate_string(value, index)
139
157
  namespace = index.nil? ? Object.new : OpenStruct.new(index: index)
140
- value.is_a?(String) ? ERB.new(value).result(namespace.instance_eval { binding }) : value
158
+ if value.is_a?(String)
159
+ return ERB.new(value).result(namespace.instance_eval { binding })
160
+ else
161
+ return value
162
+ end
141
163
  end
142
164
 
143
- # Helper method to set a value to a setting from a section (i.e. indexer, source) if the section has this setting.
165
+ # Helper method to set a value to a setting from a section (i.e. indexer,
166
+ # source) if the section has this setting.
144
167
  # If the setting is not avaiable on the section, nothing is done
145
168
  #
146
- # @param section [Riddle::Configuration::Section] a configuration section to define the setting
169
+ # @param section [Riddle::Configuration::Section] a configuration section
170
+ # to define the setting
147
171
  # @param setting [Symbol] the setting that will be defined on the section
148
172
  # @param value [Object] the value of the setting
149
173
  def setter(section, setting, value)