mongoid-giza 0.6.0 → 0.6.1
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 +4 -4
 - data/.travis.yml +2 -2
 - data/CHANGELOG.md +5 -0
 - data/lib/mongoid/giza.rb +1 -0
 - data/lib/mongoid/giza/index/attribute.rb +5 -2
 - data/lib/mongoid/giza/index/common.rb +19 -0
 - data/lib/mongoid/giza/index/field.rb +5 -2
 - data/lib/mongoid/giza/version.rb +1 -1
 - data/spec/mongoid/giza/index/common_spec.rb +13 -0
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: e88568de3ce6ba2000674119e6c9037e8c1955a1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cc83403e36c7876e6949f2cee0cdc17ecaa6afb9
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2f4760e98e0074811b7de2dc0f778a266c740f0bfb5e4150a6005fee514c0c293c2402756f9a0ff376d77a4cfdcea47238dae9a660120096cfe571d3e4d4d35d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 657c50a1c0647c2ddb9be644f17745afab69e5ba3e9fa4d5f0d8842c994f8ff8322a6f9ddfbede605acb5b911ada2f21171720035ad83423fd2b6ab8de3b129f
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        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 : 
     | 
| 
      
 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 
     | 
| 
      
 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 
     | 
    
         
            -
                     
     | 
| 
      
 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 
     | 
| 
      
 25 
     | 
    
         
            +
                      @name = normalize(name)
         
     | 
| 
       23 
26 
     | 
    
         
             
                      @attribute = attribute
         
     | 
| 
       24 
27 
     | 
    
         
             
                      @block = block
         
     | 
| 
       25 
28 
     | 
    
         
             
                    end
         
     | 
    
        data/lib/mongoid/giza/version.rb
    CHANGED
    
    
| 
         @@ -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. 
     | 
| 
      
 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- 
     | 
| 
      
 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
         
     |