mongoid-giza 0.2.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f6a99c02c683342e9631890d5db0c9f536dc48a
4
- data.tar.gz: 130064b3c93bae3095777d233fbd2bd386efc2d8
3
+ metadata.gz: 879640b0caf8a604f0bd1c30a4f2e28fe8701ebd
4
+ data.tar.gz: 1574d2f43cc5dd16e9012f6567162c161f59d7af
5
5
  SHA512:
6
- metadata.gz: 3ea89da7a5ceb6837f4fa27a8e1a00610bd730aad3d4852e72b6c62f0d17bca2e9cecec05b7508e0d6aaaa7835c7421ba0e6b2024b826a269c77802c86168671
7
- data.tar.gz: c46b77df7db788fed17b0f6219340a335f3d29a2acdfda8d87f3b3688664a303e9dc14c104964cfe743c68629d2a2759145baa4cb1416190a03c90a0c6c5506d
6
+ metadata.gz: fde8f8c1aaee58cd6e3bdce7cd91c68681052d52ae392bc8d31f331b0a591e47febe5743654a077ea8280985ff28b89d46ec9ea9df5426761db0ff1fd72fa34f
7
+ data.tar.gz: c949aee6ad8406d3d2b618cda8497769a3345544c7d5d79523c7d652e5777806cb51d8ab8a4ab9e749b8d74d5e57c597c7460a7a39d547f809cf1f51d8b562e8
data/.travis.yml CHANGED
@@ -2,5 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
5
6
  services:
6
7
  - mongodb
data/CHANGELOG.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ * Downcase all fields' and attributes' names
6
+ * Made possible to selective remove generated indexes from the configuration -- `Mongoid::Giza::Configuration#remove_generated_indexes`
7
+ * Made possible to remove from the configuratio only the generated indexes of a model -- `Mongoid::Giza::clear_generated_sphinx_indexes_configuration`
8
+
3
9
  ## 0.2.0
4
10
 
5
11
  * Use ERB to parse string settings of every section of the configuration
6
-
7
12
  * Renamed `Mongoid::Giza::Indexer::full_index` to `Mongoid::Giza::Indexer::full_index!`
8
-
9
13
  * Always convert `Mongoid::Giza::Index::Field` and `Mongoid::Giza::Index::Attribute` names to symbol
10
14
 
11
15
  ## 0.1.0
@@ -117,6 +117,15 @@ module Mongoid
117
117
  @generated_indexes = {}
118
118
  end
119
119
 
120
+ # Removes Riddle::Index's specifieds as params
121
+ #
122
+ # @param indexes [Array<Symbol>] names of indexes that should be removed
123
+ def remove_generated_indexes(indexes)
124
+ indexes.each do |index|
125
+ indices.delete(@generated_indexes.delete(index))
126
+ end
127
+ end
128
+
120
129
  # Interpolates a value if it's a String using ERB.
121
130
  # Useful for defining dynamic settings.
122
131
  # The ERB template may reference to the current {Mongoid::Giza::Index} and it's methods
@@ -29,7 +29,7 @@ module Mongoid
29
29
  "attribute type not supported. " \
30
30
  "It must be one of the following: " \
31
31
  "#{Mongoid::Giza::Index::Attribute::TYPES.join(", ")}" unless Mongoid::Giza::Index::Attribute::TYPES.include? type
32
- @name = name.to_sym
32
+ @name = name.to_s.mb_chars.downcase.to_sym
33
33
  @type = type
34
34
  @block = block
35
35
  end
@@ -17,7 +17,7 @@ module Mongoid
17
17
  # (see {http://sphinxsearch.com/docs/current.html#conf-xmlpipe-field-string})
18
18
  # @param block [Proc] an optional block to be evaluated at the scope of the document on index creation
19
19
  def initialize(name, attribute = false, &block)
20
- @name = name.to_sym
20
+ @name = name.to_s.mb_chars.downcase.to_sym
21
21
  @attribute = attribute
22
22
  @block = block
23
23
  end
@@ -48,8 +48,8 @@ module Mongoid
48
48
  # Otherwise the field value will be the value of the corresponding object field
49
49
  #
50
50
  # @param name [Symbol] the name of the field
51
- # @param options [Hash] an optional hash of options.
52
- # Currently only the boolean option :attribute is avaiable (see {Mongoid::Giza::Index::Field#initialize})
51
+ # @param options [Hash] options for the field.
52
+ # @option options [TrueClass, FalseClass] :attribute whether the field will also be a attribute or not (see {Mongoid::Giza::Index::Field#initialize})
53
53
  # @param block [Proc] an optional block to be evaluated at the scope of the document on index creation
54
54
  def field(name, options = {}, &block)
55
55
  attribute = options[:attribute].nil? ? false : true
@@ -86,6 +86,11 @@ module Mongoid
86
86
  @name = new_name || @name.to_sym
87
87
  end
88
88
 
89
+ # Defines the Mongoid::Criteria that will be used to retrive objects when indexing.
90
+ # Use this to filter what objects from the class will be indexed.
91
+ # When an index is created the criteria is defined as class.all
92
+ #
93
+ #@param new_criteria [Mongoid::Criteria] the criteria to be used
89
94
  def criteria(new_criteria = nil)
90
95
  @criteria = new_criteria || @criteria
91
96
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Giza
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/lib/mongoid/giza.rb CHANGED
@@ -131,6 +131,11 @@ module Mongoid
131
131
  dynamic_sphinx_indexes.each { |dynamic_index| process_dynamic_sphinx_index(dynamic_index) }
132
132
  end
133
133
 
134
+ # Removes all generated indexes of the class from the configuration
135
+ def clear_generated_sphinx_indexes_configuration
136
+ @giza_configuration.remove_generated_indexes(generated_sphinx_indexes.keys)
137
+ end
138
+
134
139
  # Execute the indexing routines of the indexes defined on the class.
135
140
  # This means (re)create the sphinx configuration file and then execute the indexer program on it.
136
141
  # If no index names are supplied than all indexes defined on the class will be indexed.
data/mongoid-giza.gemspec CHANGED
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency "riddle", ">= 1.5"
30
30
  spec.add_runtime_dependency "builder", ">= 3.0"
31
31
  spec.add_runtime_dependency "docile", ">= 1.1"
32
+ spec.add_runtime_dependency "activesupport"
32
33
  end
@@ -326,15 +326,17 @@ describe Mongoid::Giza::Configuration do
326
326
  describe "clear_generated_indexes" do
327
327
  let(:indices) { double("indices") }
328
328
 
329
- it "should delete the generated riddle indexes" do
329
+ before do
330
330
  @config.instance_variable_set("@generated_indexes", {name: :index})
331
+ end
332
+
333
+ it "should delete the generated riddle indexes" do
331
334
  allow(@config).to receive(:indices) { indices }
332
335
  expect(indices).to receive(:delete).with(:index)
333
336
  @config.clear_generated_indexes
334
337
  end
335
338
 
336
339
  it "should clear the generated indexes collection" do
337
- @config.instance_variable_set("@generated_indexes", {name: :index})
338
340
  @config.clear_generated_indexes
339
341
  expect(@config.instance_variable_get("@generated_indexes")).to eql({})
340
342
  end
@@ -360,4 +362,23 @@ describe Mongoid::Giza::Configuration do
360
362
  @config.setter(section, :setting, value)
361
363
  end
362
364
  end
365
+
366
+ describe "remove_generated_indexes" do
367
+ let(:indices) { double("indices") }
368
+
369
+ before do
370
+ @config.instance_variable_set("@generated_indexes", {name: :index, two: :index2})
371
+ end
372
+
373
+ it "should remove the indexes from the indices array" do
374
+ allow(@config).to receive(:indices) { indices }
375
+ expect(indices).to receive(:delete).with(:index)
376
+ @config.remove_generated_indexes([:name])
377
+ end
378
+
379
+ it "should remove the index from the generated indexes collection" do
380
+ @config.remove_generated_indexes([:name])
381
+ expect(@config.instance_variable_get("@generated_indexes")).not_to include(name: :index)
382
+ end
383
+ end
363
384
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Mongoid::Giza::Index::Attribute do
@@ -7,10 +9,36 @@ describe Mongoid::Giza::Index::Attribute do
7
9
  end
8
10
 
9
11
  it "should be set on creation" do
12
+ name = :attribute
13
+ attribute = Mongoid::Giza::Index::Attribute.new(name, :uint)
14
+ expect(attribute.name).to eql(name)
15
+ end
16
+
17
+ it "should be converted to symbol" do
10
18
  name = "attribute"
11
19
  attribute = Mongoid::Giza::Index::Attribute.new(name, :uint)
12
20
  expect(attribute.name).to eql(name.to_sym)
13
21
  end
22
+
23
+ it "should be downcased" do
24
+ attribute = Mongoid::Giza::Index::Attribute.new("Attribute", :uint)
25
+ expect(attribute.name).to eql(:attribute)
26
+ end
27
+
28
+ it "should downcase unicode chars" do
29
+ attribute = Mongoid::Giza::Index::Attribute.new("ESPAÑOL", :uint)
30
+ expect(attribute.name).to eql(:español)
31
+ end
32
+
33
+ it "should downcase symbols" do
34
+ attribute = Mongoid::Giza::Index::Attribute.new(:Attribute, :uint)
35
+ expect(attribute.name).to eql(:attribute)
36
+ end
37
+
38
+ it "should downcase unicode symbols" do
39
+ attribute = Mongoid::Giza::Index::Attribute.new(:ESPAÑOL, :uint)
40
+ expect(attribute.name).to eql(:español)
41
+ end
14
42
  end
15
43
 
16
44
  describe "type" do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Mongoid::Giza::Index::Field do
@@ -7,10 +9,36 @@ describe Mongoid::Giza::Index::Field do
7
9
  end
8
10
 
9
11
  it "should be set on creation" do
12
+ name = :field
13
+ field = Mongoid::Giza::Index::Field.new(name)
14
+ expect(field.name).to eql(name)
15
+ end
16
+
17
+ it "should be converted to symbol" do
10
18
  name = "field"
11
19
  field = Mongoid::Giza::Index::Field.new(name)
12
20
  expect(field.name).to eql(name.to_sym)
13
21
  end
22
+
23
+ it "should be downcased" do
24
+ field = Mongoid::Giza::Index::Field.new("Field")
25
+ expect(field.name).to eql(:field)
26
+ end
27
+
28
+ it "should downcase unicode chars" do
29
+ field = Mongoid::Giza::Index::Field.new("ESPAÑOL")
30
+ expect(field.name).to eql(:español)
31
+ end
32
+
33
+ it "should downcase symbols" do
34
+ field = Mongoid::Giza::Index::Field.new(:Field)
35
+ expect(field.name).to eql(:field)
36
+ end
37
+
38
+ it "should downcase unicode symbols" do
39
+ field = Mongoid::Giza::Index::Field.new(:ESPAÑOL)
40
+ expect(field.name).to eql(:español)
41
+ end
14
42
  end
15
43
 
16
44
  it "should accept string attribute" do
@@ -279,4 +279,12 @@ describe Mongoid::Giza do
279
279
  Person.regenerate_dynamic_sphinx_indexes
280
280
  end
281
281
  end
282
+
283
+ describe "clear_generated_sphinx_indexes_configuration" do
284
+ it "should remove all generated indexes of this class from the configuration" do
285
+ allow(Person).to receive(:generated_sphinx_indexes) { {index1: :index, index2: :index} }
286
+ expect(config).to receive(:remove_generated_indexes).with([:index1, :index2])
287
+ Person.clear_generated_sphinx_indexes_configuration
288
+ end
289
+ end
282
290
  end
metadata CHANGED
@@ -1,155 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-giza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maurício Batista
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mongoid-rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.8.7
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.8.7
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: database_cleaner
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.2.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.2.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: mongoid
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '3.1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: riddle
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '1.5'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '1.5'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: builder
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '3.0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: docile
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '1.1'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1.1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: activesupport
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Mongoid layer for the Sphinx fulltext search server that supports block
154
168
  fields and dynamic indexes
155
169
  email:
@@ -158,8 +172,8 @@ executables: []
158
172
  extensions: []
159
173
  extra_rdoc_files: []
160
174
  files:
161
- - .gitignore
162
- - .travis.yml
175
+ - ".gitignore"
176
+ - ".travis.yml"
163
177
  - CHANGELOG.md
164
178
  - Gemfile
165
179
  - LICENSE.txt
@@ -199,17 +213,17 @@ require_paths:
199
213
  - lib
200
214
  required_ruby_version: !ruby/object:Gem::Requirement
201
215
  requirements:
202
- - - '>='
216
+ - - ">="
203
217
  - !ruby/object:Gem::Version
204
218
  version: '0'
205
219
  required_rubygems_version: !ruby/object:Gem::Requirement
206
220
  requirements:
207
- - - '>='
221
+ - - ">="
208
222
  - !ruby/object:Gem::Version
209
223
  version: '0'
210
224
  requirements: []
211
225
  rubyforge_project:
212
- rubygems_version: 2.1.11
226
+ rubygems_version: 2.2.1
213
227
  signing_key:
214
228
  specification_version: 4
215
229
  summary: Mongoid layer for the Sphinx fulltext search server