mongoid-giza 0.6.0 → 0.6.1

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: e68c24c85a8ab1a5058c90204c1b4b48c8894717
4
- data.tar.gz: 23a10d3f8db970eef859cb5b4675f15c42cdf4c7
3
+ metadata.gz: e88568de3ce6ba2000674119e6c9037e8c1955a1
4
+ data.tar.gz: cc83403e36c7876e6949f2cee0cdc17ecaa6afb9
5
5
  SHA512:
6
- metadata.gz: 7ebbc8f78cae69b1eac182a59ceadbc9b1b3c6c43f968e190d75078a812fb939df5967ba59740df6ae6304ac12eb65f2332a8d308587d4b48fe820ccef609f8f
7
- data.tar.gz: 08c98fb01da3de22b160cbebe2c8a7c69eee0124e26cfc2f5d8078d6e41f324cce8e52660c2644391570fd9742ca0195b6ca801d7b801145754608fb704bcfc9
6
+ metadata.gz: 2f4760e98e0074811b7de2dc0f778a266c740f0bfb5e4150a6005fee514c0c293c2402756f9a0ff376d77a4cfdcea47238dae9a660120096cfe571d3e4d4d35d
7
+ data.tar.gz: 657c50a1c0647c2ddb9be644f17745afab69e5ba3e9fa4d5f0d8842c994f8ff8322a6f9ddfbede605acb5b911ada2f21171720035ad83423fd2b6ab8de3b129f
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.1
6
- - 2.2.1
5
+ - 2.1.6
6
+ - 2.2.2
7
7
  services:
8
8
  - mongodb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.1
4
+
5
+ * Only allow alphabetical characters on fields' and attributes' names (replaces everything else with **-**)
6
+ * Fields' name and attributes' name and type are read-only
7
+
3
8
  ## 0.6.0
4
9
 
5
10
  * Mongoid 4 or higher is now required
data/lib/mongoid/giza.rb CHANGED
@@ -4,6 +4,7 @@ require "riddle"
4
4
  require "mongoid/giza/configuration"
5
5
  require "mongoid/giza/dynamic_index"
6
6
  require "mongoid/giza/index"
7
+ require "mongoid/giza/index/common"
7
8
  require "mongoid/giza/index/field"
8
9
  require "mongoid/giza/index/attribute"
9
10
  require "mongoid/giza/indexer"
@@ -3,13 +3,16 @@ module Mongoid
3
3
  class Index
4
4
  # Represents a Sphinx index attribute
5
5
  class Attribute
6
+ include Common
7
+
6
8
  # Defines the array of currently supported Sphix attribute types
7
9
  TYPES = [
8
10
  :uint, :bool, :bigint, :timestamp, :float,
9
11
  :multi, :multi_64, :string, :json
10
12
  ]
11
13
 
12
- attr_accessor :name, :type, :default, :bits, :block
14
+ attr_accessor :default, :bits, :block
15
+ attr_reader :name, :type
13
16
 
14
17
  # Creates a new attribute with name, type and an optional block
15
18
  #
@@ -32,7 +35,7 @@ module Mongoid
32
35
  "Attribute type not supported. " \
33
36
  "It must be one of the following: " \
34
37
  "#{TYPES.join(', ')}" unless TYPES.include? type
35
- @name = name.to_s.mb_chars.downcase.to_sym
38
+ @name = normalize(name)
36
39
  @type = type
37
40
  @block = block
38
41
  @default = options[:default]
@@ -0,0 +1,19 @@
1
+ module Mongoid
2
+ module Giza
3
+ class Index
4
+ # Common routines to fields and attributes
5
+ module Common
6
+ extend ActiveSupport::Concern
7
+
8
+ # Replaces all non-alphabetical characters and converts to lower case
9
+ #
10
+ # @param s [Symbol, String] symbol or string to be normalized
11
+ #
12
+ # @return [Symbol] the normalized symbol
13
+ def normalize(s)
14
+ s.to_s.gsub(/[^[:alpha:]]/, "-").mb_chars.downcase.to_sym
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,7 +3,10 @@ module Mongoid
3
3
  class Index
4
4
  # Represents a Sphinx indexed field
5
5
  class Field
6
- attr_accessor :name, :attribute, :block
6
+ include Common
7
+
8
+ attr_accessor :attribute, :block
9
+ attr_reader :name
7
10
 
8
11
  # Creates a full-text field with a name and an optional block
9
12
  #
@@ -19,7 +22,7 @@ module Mongoid
19
22
  # @param block [Proc] an optional block to be evaluated at the scope of
20
23
  # the document on index creation
21
24
  def initialize(name, attribute = nil, &block)
22
- @name = name.to_s.mb_chars.downcase.to_sym
25
+ @name = normalize(name)
23
26
  @attribute = attribute
24
27
  @block = block
25
28
  end
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  # :nodoc:
3
3
  module Giza
4
- VERSION = "0.6.0"
4
+ VERSION = "0.6.1"
5
5
  end
6
6
  end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require "spec_helper"
4
+
5
+ describe Mongoid::Giza::Index::Common do
6
+ include Mongoid::Giza::Index::Common
7
+
8
+ describe "normalize" do
9
+ it "should replace non-alphabetic characters with a dash" do
10
+ expect(normalize("aá(")).to eql(:"aá-")
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-giza
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
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: 2015-03-26 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -199,6 +199,7 @@ files:
199
199
  - lib/mongoid/giza/dynamic_index.rb
200
200
  - lib/mongoid/giza/index.rb
201
201
  - lib/mongoid/giza/index/attribute.rb
202
+ - lib/mongoid/giza/index/common.rb
202
203
  - lib/mongoid/giza/index/field.rb
203
204
  - lib/mongoid/giza/indexer.rb
204
205
  - lib/mongoid/giza/models/id.rb
@@ -210,6 +211,7 @@ files:
210
211
  - spec/mongoid/giza/configuration_spec.rb
211
212
  - spec/mongoid/giza/dynamic_index_spec.rb
212
213
  - spec/mongoid/giza/index/attribute_spec.rb
214
+ - spec/mongoid/giza/index/common_spec.rb
213
215
  - spec/mongoid/giza/index/field_spec.rb
214
216
  - spec/mongoid/giza/index_spec.rb
215
217
  - spec/mongoid/giza/indexer_spec.rb
@@ -246,6 +248,7 @@ test_files:
246
248
  - spec/mongoid/giza/configuration_spec.rb
247
249
  - spec/mongoid/giza/dynamic_index_spec.rb
248
250
  - spec/mongoid/giza/index/attribute_spec.rb
251
+ - spec/mongoid/giza/index/common_spec.rb
249
252
  - spec/mongoid/giza/index/field_spec.rb
250
253
  - spec/mongoid/giza/index_spec.rb
251
254
  - spec/mongoid/giza/indexer_spec.rb