sql_record 1.0.4 → 1.0.5
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/Gemfile +2 -2
- data/Gemfile.lock +15 -0
- data/README.rdoc +3 -3
- data/VERSION +1 -1
- data/lib/sql_record/attributes/mapper.rb +6 -4
- data/lib/sql_record/sanitized_query.rb +17 -2
- data/sql_record.gemspec +5 -2
- metadata +32 -16
    
        data/Gemfile
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 | 
            -
            source  | 
| 1 | 
            +
            source :rubygems
         | 
| 2 2 | 
             
            # Add dependencies required to use your gem here.
         | 
| 3 3 | 
             
            # Example:
         | 
| 4 | 
            -
             | 
| 4 | 
            +
            gem "activerecord", ">= 2.3.0"
         | 
| 5 5 |  | 
| 6 6 | 
             
            # Add dependencies to develop your gem here.
         | 
| 7 7 | 
             
            # Include everything needed to run rake, tests, features, etc.
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,8 +1,21 @@ | |
| 1 1 | 
             
            GEM
         | 
| 2 2 | 
             
              remote: http://rubygems.org/
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            +
                activemodel (3.0.5)
         | 
| 5 | 
            +
                  activesupport (= 3.0.5)
         | 
| 6 | 
            +
                  builder (~> 2.1.2)
         | 
| 7 | 
            +
                  i18n (~> 0.4)
         | 
| 8 | 
            +
                activerecord (3.0.5)
         | 
| 9 | 
            +
                  activemodel (= 3.0.5)
         | 
| 10 | 
            +
                  activesupport (= 3.0.5)
         | 
| 11 | 
            +
                  arel (~> 2.0.2)
         | 
| 12 | 
            +
                  tzinfo (~> 0.3.23)
         | 
| 13 | 
            +
                activesupport (3.0.5)
         | 
| 14 | 
            +
                arel (2.0.9)
         | 
| 15 | 
            +
                builder (2.1.2)
         | 
| 4 16 | 
             
                diff-lcs (1.1.2)
         | 
| 5 17 | 
             
                git (1.2.5)
         | 
| 18 | 
            +
                i18n (0.5.0)
         | 
| 6 19 | 
             
                jeweler (1.5.2)
         | 
| 7 20 | 
             
                  bundler (~> 1.0.0)
         | 
| 8 21 | 
             
                  git (>= 1.2.5)
         | 
| @@ -18,12 +31,14 @@ GEM | |
| 18 31 | 
             
                rspec-expectations (2.3.0)
         | 
| 19 32 | 
             
                  diff-lcs (~> 1.1.2)
         | 
| 20 33 | 
             
                rspec-mocks (2.3.0)
         | 
| 34 | 
            +
                tzinfo (0.3.25)
         | 
| 21 35 | 
             
                yard (0.6.7)
         | 
| 22 36 |  | 
| 23 37 | 
             
            PLATFORMS
         | 
| 24 38 | 
             
              ruby
         | 
| 25 39 |  | 
| 26 40 | 
             
            DEPENDENCIES
         | 
| 41 | 
            +
              activerecord (>= 2.3.0)
         | 
| 27 42 | 
             
              bundler (~> 1.0.0)
         | 
| 28 43 | 
             
              jeweler (~> 1.5.2)
         | 
| 29 44 | 
             
              rcov
         | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -8,7 +8,7 @@ Well that's what SQLRecord does. | |
| 8 8 |  | 
| 9 9 | 
             
            == Example
         | 
| 10 10 |  | 
| 11 | 
            -
                class UserWithAccount  | 
| 11 | 
            +
                class UserWithAccount < SQLRecord::Base
         | 
| 12 12 |  | 
| 13 13 | 
             
                  with_opts :class => User do
         | 
| 14 14 | 
             
                    column :id
         | 
| @@ -22,9 +22,9 @@ Well that's what SQLRecord does. | |
| 22 22 |  | 
| 23 23 | 
             
                  column :account_id, :from => :id, :class => Account
         | 
| 24 24 |  | 
| 25 | 
            -
                  query do |params | 
| 25 | 
            +
                  query do |params|
         | 
| 26 26 | 
             
                    [
         | 
| 27 | 
            -
                      "SELECT #{ | 
| 27 | 
            +
                      "SELECT #{sql_select_columns.join(', ')} " +
         | 
| 28 28 | 
             
                      "FROM users INNER JOIN accounts " +
         | 
| 29 29 | 
             
                      "ON users.account_id = accounts.id " +
         | 
| 30 30 | 
             
                      "WHERE users.id = ?",
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            1.0. | 
| 1 | 
            +
            1.0.5
         | 
| @@ -29,6 +29,12 @@ module SQLRecord | |
| 29 29 | 
             
                    @default_opts = nil
         | 
| 30 30 | 
             
                  end
         | 
| 31 31 |  | 
| 32 | 
            +
                  # Sugar for with
         | 
| 33 | 
            +
                  def with_class klass, opts = {}, &block
         | 
| 34 | 
            +
                    opts[:class] = klass
         | 
| 35 | 
            +
                    with_opts opts, &block
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 32 38 | 
             
                  # Specifies the mapping from an ActiveRecord#column_definition to an SQLRecord instance attribute.
         | 
| 33 39 | 
             
                  # @param [Symbol] attribute_name the attribute you are defining for this model
         | 
| 34 40 | 
             
                  # @option opts [Class] :class the active record this attribute will use to type_cast from
         | 
| @@ -59,10 +65,6 @@ module SQLRecord | |
| 59 65 | 
             
                    (@sql_select_columns ||= []) << select_column
         | 
| 60 66 | 
             
                  end
         | 
| 61 67 |  | 
| 62 | 
            -
                  def sql_select_helper
         | 
| 63 | 
            -
                     @sql_select_columns.join(', ')
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
             | 
| 66 68 | 
             
                end
         | 
| 67 69 | 
             
              end
         | 
| 68 70 | 
             
            end
         | 
| @@ -11,6 +11,15 @@ module SQLRecord | |
| 11 11 | 
             
                  end
         | 
| 12 12 | 
             
                end
         | 
| 13 13 |  | 
| 14 | 
            +
                # Specifies the query to execute
         | 
| 15 | 
            +
                # @yield the block that will be executed with each {#find}
         | 
| 16 | 
            +
                # @yieldparam [Hash] params the parametrs passed in from {#find}
         | 
| 17 | 
            +
                # @yieldreturn [Array, String] Either the sql string or a sanitize array to be executed.
         | 
| 18 | 
            +
                # @note
         | 
| 19 | 
            +
                #   do not try to sanitize identifiers, only values will sanitize well
         | 
| 20 | 
            +
                #     ["where id = ?", 1] => "where id = 1"
         | 
| 21 | 
            +
                #     ["where name = ?", "hello"] => "where id = 'hello'"
         | 
| 22 | 
            +
                #     ["ORDER BY ? ASC", "id"] => "ORDER BY 'id' ASC"  << not legitimate SQL
         | 
| 14 23 | 
             
                def query &deferred
         | 
| 15 24 | 
             
                  @query_proc = deferred
         | 
| 16 25 | 
             
                end
         | 
| @@ -18,12 +27,18 @@ module SQLRecord | |
| 18 27 | 
             
                protected
         | 
| 19 28 |  | 
| 20 29 | 
             
                # @todo check that this logs the sql
         | 
| 30 | 
            +
                # @todo Write own sanitizer: (http://www.ruby-forum.com/topic/187658)
         | 
| 31 | 
            +
                #   sanitize_sql_array sanitizes values correctly, not identifiers, eg:
         | 
| 32 | 
            +
                #   ["where id = ?", 1] => "where id = 1"
         | 
| 33 | 
            +
                #   ["where name = ?", "hello"] => "where id = 'hello'"
         | 
| 34 | 
            +
                #   ["ORDER BY ? ASC", "id"] => "ORDER BY 'id' ASC"  << not legitimate SQL
         | 
| 21 35 | 
             
                def execute_query params={}
         | 
| 22 | 
            -
                  sql =  | 
| 36 | 
            +
                  sql = get_query(params)
         | 
| 37 | 
            +
                  sql = ActiveRecord::Base.send(:sanitize_sql_array, sql) if sql.is_a?(Array)
         | 
| 23 38 | 
             
                  ActiveRecord::Base.connection.execute(sql)
         | 
| 24 39 | 
             
                end
         | 
| 25 40 |  | 
| 26 | 
            -
                def  | 
| 41 | 
            +
                def get_query(params)
         | 
| 27 42 | 
             
                    @query_proc.call(params)
         | 
| 28 43 | 
             
                end
         | 
| 29 44 |  | 
    
        data/sql_record.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{sql_record}
         | 
| 8 | 
            -
              s.version = "1.0. | 
| 8 | 
            +
              s.version = "1.0.5"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Rasheed Abdul-Aziz"]
         | 
| 12 | 
            -
              s.date = %q{2011-04- | 
| 12 | 
            +
              s.date = %q{2011-04-11}
         | 
| 13 13 | 
             
              s.description = %q{Do you use ActiveRecord::Connection.execute for speed sometimes? Does it bother you that the results are not mapped to your schema and type-cast as ActiveRecord would? Well that's what SQLRecord does.}
         | 
| 14 14 | 
             
              s.email = %q{rasheed@visfleet.com}
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
| @@ -52,6 +52,7 @@ Gem::Specification.new do |s| | |
| 52 52 | 
             
                s.specification_version = 3
         | 
| 53 53 |  | 
| 54 54 | 
             
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 55 | 
            +
                  s.add_runtime_dependency(%q<activerecord>, [">= 2.3.0"])
         | 
| 55 56 | 
             
                  s.add_development_dependency(%q<rdoc>, [">= 0"])
         | 
| 56 57 | 
             
                  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
         | 
| 57 58 | 
             
                  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
         | 
| @@ -59,6 +60,7 @@ Gem::Specification.new do |s| | |
| 59 60 | 
             
                  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
         | 
| 60 61 | 
             
                  s.add_development_dependency(%q<rcov>, [">= 0"])
         | 
| 61 62 | 
             
                else
         | 
| 63 | 
            +
                  s.add_dependency(%q<activerecord>, [">= 2.3.0"])
         | 
| 62 64 | 
             
                  s.add_dependency(%q<rdoc>, [">= 0"])
         | 
| 63 65 | 
             
                  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
         | 
| 64 66 | 
             
                  s.add_dependency(%q<yard>, ["~> 0.6.0"])
         | 
| @@ -67,6 +69,7 @@ Gem::Specification.new do |s| | |
| 67 69 | 
             
                  s.add_dependency(%q<rcov>, [">= 0"])
         | 
| 68 70 | 
             
                end
         | 
| 69 71 | 
             
              else
         | 
| 72 | 
            +
                s.add_dependency(%q<activerecord>, [">= 2.3.0"])
         | 
| 70 73 | 
             
                s.add_dependency(%q<rdoc>, [">= 0"])
         | 
| 71 74 | 
             
                s.add_dependency(%q<rspec>, ["~> 2.3.0"])
         | 
| 72 75 | 
             
                s.add_dependency(%q<yard>, ["~> 0.6.0"])
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: sql_record
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 29
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.0. | 
| 9 | 
            +
              - 5
         | 
| 10 | 
            +
              version: 1.0.5
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Rasheed Abdul-Aziz
         | 
| @@ -15,12 +15,28 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011-04- | 
| 18 | 
            +
            date: 2011-04-11 00:00:00 +00:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 22 | 
            -
              name:  | 
| 22 | 
            +
              name: activerecord
         | 
| 23 23 | 
             
              version_requirements: &id001 !ruby/object:Gem::Requirement 
         | 
| 24 | 
            +
                none: false
         | 
| 25 | 
            +
                requirements: 
         | 
| 26 | 
            +
                - - ">="
         | 
| 27 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 28 | 
            +
                    hash: 3
         | 
| 29 | 
            +
                    segments: 
         | 
| 30 | 
            +
                    - 2
         | 
| 31 | 
            +
                    - 3
         | 
| 32 | 
            +
                    - 0
         | 
| 33 | 
            +
                    version: 2.3.0
         | 
| 34 | 
            +
              prerelease: false
         | 
| 35 | 
            +
              type: :runtime
         | 
| 36 | 
            +
              requirement: *id001
         | 
| 37 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 38 | 
            +
              name: rdoc
         | 
| 39 | 
            +
              version_requirements: &id002 !ruby/object:Gem::Requirement 
         | 
| 24 40 | 
             
                none: false
         | 
| 25 41 | 
             
                requirements: 
         | 
| 26 42 | 
             
                - - ">="
         | 
| @@ -31,10 +47,10 @@ dependencies: | |
| 31 47 | 
             
                    version: "0"
         | 
| 32 48 | 
             
              prerelease: false
         | 
| 33 49 | 
             
              type: :development
         | 
| 34 | 
            -
              requirement: * | 
| 50 | 
            +
              requirement: *id002
         | 
| 35 51 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 36 52 | 
             
              name: rspec
         | 
| 37 | 
            -
              version_requirements: & | 
| 53 | 
            +
              version_requirements: &id003 !ruby/object:Gem::Requirement 
         | 
| 38 54 | 
             
                none: false
         | 
| 39 55 | 
             
                requirements: 
         | 
| 40 56 | 
             
                - - ~>
         | 
| @@ -47,10 +63,10 @@ dependencies: | |
| 47 63 | 
             
                    version: 2.3.0
         | 
| 48 64 | 
             
              prerelease: false
         | 
| 49 65 | 
             
              type: :development
         | 
| 50 | 
            -
              requirement: * | 
| 66 | 
            +
              requirement: *id003
         | 
| 51 67 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 52 68 | 
             
              name: yard
         | 
| 53 | 
            -
              version_requirements: & | 
| 69 | 
            +
              version_requirements: &id004 !ruby/object:Gem::Requirement 
         | 
| 54 70 | 
             
                none: false
         | 
| 55 71 | 
             
                requirements: 
         | 
| 56 72 | 
             
                - - ~>
         | 
| @@ -63,10 +79,10 @@ dependencies: | |
| 63 79 | 
             
                    version: 0.6.0
         | 
| 64 80 | 
             
              prerelease: false
         | 
| 65 81 | 
             
              type: :development
         | 
| 66 | 
            -
              requirement: * | 
| 82 | 
            +
              requirement: *id004
         | 
| 67 83 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 68 84 | 
             
              name: bundler
         | 
| 69 | 
            -
              version_requirements: & | 
| 85 | 
            +
              version_requirements: &id005 !ruby/object:Gem::Requirement 
         | 
| 70 86 | 
             
                none: false
         | 
| 71 87 | 
             
                requirements: 
         | 
| 72 88 | 
             
                - - ~>
         | 
| @@ -79,10 +95,10 @@ dependencies: | |
| 79 95 | 
             
                    version: 1.0.0
         | 
| 80 96 | 
             
              prerelease: false
         | 
| 81 97 | 
             
              type: :development
         | 
| 82 | 
            -
              requirement: * | 
| 98 | 
            +
              requirement: *id005
         | 
| 83 99 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 84 100 | 
             
              name: jeweler
         | 
| 85 | 
            -
              version_requirements: & | 
| 101 | 
            +
              version_requirements: &id006 !ruby/object:Gem::Requirement 
         | 
| 86 102 | 
             
                none: false
         | 
| 87 103 | 
             
                requirements: 
         | 
| 88 104 | 
             
                - - ~>
         | 
| @@ -95,10 +111,10 @@ dependencies: | |
| 95 111 | 
             
                    version: 1.5.2
         | 
| 96 112 | 
             
              prerelease: false
         | 
| 97 113 | 
             
              type: :development
         | 
| 98 | 
            -
              requirement: * | 
| 114 | 
            +
              requirement: *id006
         | 
| 99 115 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 100 116 | 
             
              name: rcov
         | 
| 101 | 
            -
              version_requirements: & | 
| 117 | 
            +
              version_requirements: &id007 !ruby/object:Gem::Requirement 
         | 
| 102 118 | 
             
                none: false
         | 
| 103 119 | 
             
                requirements: 
         | 
| 104 120 | 
             
                - - ">="
         | 
| @@ -109,7 +125,7 @@ dependencies: | |
| 109 125 | 
             
                    version: "0"
         | 
| 110 126 | 
             
              prerelease: false
         | 
| 111 127 | 
             
              type: :development
         | 
| 112 | 
            -
              requirement: * | 
| 128 | 
            +
              requirement: *id007
         | 
| 113 129 | 
             
            description: Do you use ActiveRecord::Connection.execute for speed sometimes? Does it bother you that the results are not mapped to your schema and type-cast as ActiveRecord would? Well that's what SQLRecord does.
         | 
| 114 130 | 
             
            email: rasheed@visfleet.com
         | 
| 115 131 | 
             
            executables: []
         |