squeel 0.9.1 → 0.9.2
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.
- data/lib/squeel/nodes/join.rb +5 -0
- data/lib/squeel/nodes/key_path.rb +15 -1
- data/lib/squeel/nodes/sifter.rb +13 -0
- data/lib/squeel/nodes/stub.rb +6 -0
- data/lib/squeel/version.rb +1 -1
- data/spec/squeel/nodes/key_path_spec.rb +6 -0
- data/spec/squeel/nodes/stub_spec.rb +6 -0
- data/spec/squeel/visitors/predicate_visitor_spec.rb +9 -0
- metadata +16 -16
    
        data/lib/squeel/nodes/join.rb
    CHANGED
    
    
| @@ -109,7 +109,21 @@ module Squeel | |
| 109 109 | 
             
                  # @param other The right hand side of the operation
         | 
| 110 110 | 
             
                  # @return [Operation] An operation with the given custom operator, the KeyPath on its left and the other object on the right.
         | 
| 111 111 | 
             
                  def op(operator, other)
         | 
| 112 | 
            -
                    endpoint.respond_to?(:op) ? super : no_method_error( | 
| 112 | 
            +
                    endpoint.respond_to?(:op) ? super : no_method_error(:op)
         | 
| 113 | 
            +
                  end
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                  # Allow KeyPath to have a sifter as its endpoint, if the endpoint is a
         | 
| 116 | 
            +
                  # chainable node (Stub or Join)
         | 
| 117 | 
            +
                  # @param [Symbol] name The name of the sifter
         | 
| 118 | 
            +
                  # @return [KeyPath] This keypath, with a sifter as its endpoint
         | 
| 119 | 
            +
                  def sift(name, *args)
         | 
| 120 | 
            +
                    if Stub === endpoint || Join === endpoint
         | 
| 121 | 
            +
                      @path << endpoint
         | 
| 122 | 
            +
                      @endpoint = Sifter.new(name, args)
         | 
| 123 | 
            +
                      self
         | 
| 124 | 
            +
                    else
         | 
| 125 | 
            +
                      no_method_error :sift
         | 
| 126 | 
            +
                    end
         | 
| 113 127 | 
             
                  end
         | 
| 114 128 |  | 
| 115 129 | 
             
                  # Set the absolute flag on this KeyPath
         | 
    
        data/lib/squeel/nodes/sifter.rb
    CHANGED
    
    | @@ -9,6 +9,19 @@ module Squeel | |
| 9 9 | 
             
                    @name, @args = name, args
         | 
| 10 10 | 
             
                  end
         | 
| 11 11 |  | 
| 12 | 
            +
                  # Implemented for equality testing
         | 
| 13 | 
            +
                  def hash
         | 
| 14 | 
            +
                    [name, args].hash
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  # Compare with other objects
         | 
| 18 | 
            +
                  def eql?(other)
         | 
| 19 | 
            +
                    self.class.eql?(other.class) &&
         | 
| 20 | 
            +
                    self.name.eql?(other.name) &&
         | 
| 21 | 
            +
                    self.args.eql?(other.args)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
                  alias :== :eql?
         | 
| 24 | 
            +
             | 
| 12 25 | 
             
                end
         | 
| 13 26 | 
             
              end
         | 
| 14 27 | 
             
            end
         | 
    
        data/lib/squeel/nodes/stub.rb
    CHANGED
    
    | @@ -108,6 +108,12 @@ module Squeel | |
| 108 108 | 
             
                    Join.new(self.symbol, Arel::InnerJoin)
         | 
| 109 109 | 
             
                  end
         | 
| 110 110 |  | 
| 111 | 
            +
                  # Create a keypath with a sifter as its endpoint
         | 
| 112 | 
            +
                  # @return [KeyPath] The new KeyPath
         | 
| 113 | 
            +
                  def sift(name, *args)
         | 
| 114 | 
            +
                    KeyPath.new(self, Sifter.new(name, args))
         | 
| 115 | 
            +
                  end
         | 
| 116 | 
            +
             | 
| 111 117 | 
             
                  # Create an outer Join node for the association named by this Stub
         | 
| 112 118 | 
             
                  # @return [Join] The new outer Join node
         | 
| 113 119 | 
             
                  def outer
         | 
    
        data/lib/squeel/version.rb
    CHANGED
    
    
| @@ -55,6 +55,12 @@ module Squeel | |
| 55 55 | 
             
                    as.right.should eq 'other_name'
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 |  | 
| 58 | 
            +
                  it 'creates sifter nodes with #sift' do
         | 
| 59 | 
            +
                    @k.sift(:blah, 1)
         | 
| 60 | 
            +
                    sifter = @k.endpoint
         | 
| 61 | 
            +
                    sifter.should be_a Sifter
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 58 64 | 
             
                  it 'creates AND nodes with & if the endpoint responds to &' do
         | 
| 59 65 | 
             
                    node = @k.third.fourth.eq('Bob') & Stub.new(:attr).eq('Joe')
         | 
| 60 66 | 
             
                    node.should be_a And
         | 
| @@ -39,6 +39,12 @@ module Squeel | |
| 39 39 | 
             
                    keypath.path_with_endpoint.should eq [@s, Join.new(:another, Arel::InnerJoin, Person)]
         | 
| 40 40 | 
             
                  end
         | 
| 41 41 |  | 
| 42 | 
            +
                  it 'creates a KeyPath with a sifter endpoint when sent #sift' do
         | 
| 43 | 
            +
                    keypath = @s.sift(:blah, 1)
         | 
| 44 | 
            +
                    keypath.should be_a KeyPath
         | 
| 45 | 
            +
                    keypath.path_with_endpoint.should eq [@s, Sifter.new(:blah, [1])]
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 42 48 | 
             
                  it 'creates an absolute keypath with just an endpoint with ~' do
         | 
| 43 49 | 
             
                    node = ~@s
         | 
| 44 50 | 
             
                    node.should be_a KeyPath
         | 
| @@ -272,6 +272,15 @@ module Squeel | |
| 272 272 | 
             
                    expr.right.to_sql.should match /"children_people"."name" LIKE '%smith'/
         | 
| 273 273 | 
             
                  end
         | 
| 274 274 |  | 
| 275 | 
            +
                  it 'visits sifters in a keypath' do
         | 
| 276 | 
            +
                    predicate = @v.accept(dsl {children.sift(:name_starts_or_ends_with, 'smith')})
         | 
| 277 | 
            +
                    predicate.should be_a Arel::Nodes::Grouping
         | 
| 278 | 
            +
                    expr = predicate.expr
         | 
| 279 | 
            +
                    expr.should be_a Arel::Nodes::Or
         | 
| 280 | 
            +
                    expr.left.to_sql.should match /"children_people"."name" LIKE 'smith%'/
         | 
| 281 | 
            +
                    expr.right.to_sql.should match /"children_people"."name" LIKE '%smith'/
         | 
| 282 | 
            +
                  end
         | 
| 283 | 
            +
             | 
| 275 284 | 
             
                  it 'honors an explicit table in string keys' do
         | 
| 276 285 | 
             
                    predicate = @v.accept('things.attribute' => 'retro')
         | 
| 277 286 | 
             
                    predicate.should be_a Arel::Nodes::Equality
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: squeel
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.9. | 
| 4 | 
            +
              version: 0.9.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2011-09- | 
| 12 | 
            +
            date: 2011-09-29 00:00:00.000000000Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: activerecord
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &70246229519260 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ~>
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: '3.0'
         | 
| 22 22 | 
             
              type: :runtime
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *70246229519260
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: activesupport
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &70246229518440 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ~>
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: '3.0'
         | 
| 33 33 | 
             
              type: :runtime
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *70246229518440
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: polyamorous
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &70246229517800 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ~>
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: 0.5.0
         | 
| 44 44 | 
             
              type: :runtime
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *70246229517800
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: rspec
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &70246229517260 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ~>
         | 
| @@ -54,10 +54,10 @@ dependencies: | |
| 54 54 | 
             
                    version: 2.6.0
         | 
| 55 55 | 
             
              type: :development
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 57 | 
            +
              version_requirements: *70246229517260
         | 
| 58 58 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 59 59 | 
             
              name: machinist
         | 
| 60 | 
            -
              requirement: & | 
| 60 | 
            +
              requirement: &70246229516760 !ruby/object:Gem::Requirement
         | 
| 61 61 | 
             
                none: false
         | 
| 62 62 | 
             
                requirements:
         | 
| 63 63 | 
             
                - - ~>
         | 
| @@ -65,10 +65,10 @@ dependencies: | |
| 65 65 | 
             
                    version: 1.0.6
         | 
| 66 66 | 
             
              type: :development
         | 
| 67 67 | 
             
              prerelease: false
         | 
| 68 | 
            -
              version_requirements: * | 
| 68 | 
            +
              version_requirements: *70246229516760
         | 
| 69 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 70 | 
             
              name: faker
         | 
| 71 | 
            -
              requirement: & | 
| 71 | 
            +
              requirement: &70246229516300 !ruby/object:Gem::Requirement
         | 
| 72 72 | 
             
                none: false
         | 
| 73 73 | 
             
                requirements:
         | 
| 74 74 | 
             
                - - ~>
         | 
| @@ -76,10 +76,10 @@ dependencies: | |
| 76 76 | 
             
                    version: 0.9.5
         | 
| 77 77 | 
             
              type: :development
         | 
| 78 78 | 
             
              prerelease: false
         | 
| 79 | 
            -
              version_requirements: * | 
| 79 | 
            +
              version_requirements: *70246229516300
         | 
| 80 80 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 81 81 | 
             
              name: sqlite3
         | 
| 82 | 
            -
              requirement: & | 
| 82 | 
            +
              requirement: &70246229515840 !ruby/object:Gem::Requirement
         | 
| 83 83 | 
             
                none: false
         | 
| 84 84 | 
             
                requirements:
         | 
| 85 85 | 
             
                - - ~>
         | 
| @@ -87,7 +87,7 @@ dependencies: | |
| 87 87 | 
             
                    version: 1.3.3
         | 
| 88 88 | 
             
              type: :development
         | 
| 89 89 | 
             
              prerelease: false
         | 
| 90 | 
            -
              version_requirements: * | 
| 90 | 
            +
              version_requirements: *70246229515840
         | 
| 91 91 | 
             
            description: ! "\n      Squeel unlocks the power of ARel in your Rails 3 application
         | 
| 92 92 | 
             
              with\n      a handy block-based syntax. You can write subqueries, access named\n
         | 
| 93 93 | 
             
              \     functions provided by your RDBMS, and more, all without writing\n      SQL
         |