order_order 0.0.1 → 1.0.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 +4 -4
- data/lib/order_order/extensions.rb +47 -0
- data/lib/order_order/version.rb +1 -1
- data/lib/order_order.rb +1 -4
- data/order_order.gemspec +2 -0
- metadata +16 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a26645f321275ccfdaa5139bf30ff8a9665988f9
         | 
| 4 | 
            +
              data.tar.gz: 5007c39623d4b65dbfe2c56d2be9abc81859cb91
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2077144f2407104227e9d3bfd4588607689f00a8c34cf9f2472c12f16c1ec5e48b1b632f584ed26477362c43d72c6e691712df4658b4d3a866d54de4cd410607
         | 
| 7 | 
            +
              data.tar.gz: cd46ef598a7371cd7904456fafc3111d076642264d9e239d74c2177aa0c6fd9b3393f077ac1fc6183923d49c759c281d761b4fdc033442ce349713039d8ea1d6
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            # Extension for ActiveRecord::Base which adds some common sorting options.
         | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
            # WARNING: **Never** allow allow user-generated input to be passed in as the
         | 
| 4 | 
            +
            # values of these methods! It would leave you wide open to SQL injection.
         | 
| 5 | 
            +
            module OrderOrder
         | 
| 6 | 
            +
              module Extensions
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                # Order records by date, with the newest records first.
         | 
| 9 | 
            +
                #
         | 
| 10 | 
            +
                # @param column [String] the name of the column which represents the object's
         | 
| 11 | 
            +
                # date. Defaults to `created_at`
         | 
| 12 | 
            +
                def chronological(column=:created_at)
         | 
| 13 | 
            +
                  order("#{column} ASC")
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                # Order records by date, with the oldest records first.
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                # @param column [String] the name of the column which represents the object's
         | 
| 19 | 
            +
                # date. Defaults to `created_at`
         | 
| 20 | 
            +
                def reverse_chronological(column=:created_at)
         | 
| 21 | 
            +
                  order("#{column} DESC")
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                # Order records alphabetically.
         | 
| 25 | 
            +
                #
         | 
| 26 | 
            +
                # @param column [String] the name of the column which represents the object's
         | 
| 27 | 
            +
                #   name. Defaults to `name`
         | 
| 28 | 
            +
                def alphabetical(column=:name)
         | 
| 29 | 
            +
                  order("#{column} ASC")
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                # Order records reverse alphabetically.
         | 
| 33 | 
            +
                #
         | 
| 34 | 
            +
                # @param column [String] the name of the column which represents the object's
         | 
| 35 | 
            +
                #   name. Defaults to `name`
         | 
| 36 | 
            +
                def reverse_alphabetical(column=:name)
         | 
| 37 | 
            +
                  order("#{column} DESC")
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                # TODO A potential way to improve this: setting `self.chronological_column`
         | 
| 41 | 
            +
                # or `self.name_column` at the model level would negate the need to pass an
         | 
| 42 | 
            +
                # argument to these methods.
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            ActiveRecord::Base.send(:extend, OrderOrder::Extensions)
         | 
    
        data/lib/order_order/version.rb
    CHANGED
    
    
    
        data/lib/order_order.rb
    CHANGED
    
    
    
        data/order_order.gemspec
    CHANGED
    
    | @@ -18,6 +18,8 @@ Gem::Specification.new do |spec| | |
| 18 18 | 
             
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         | 
| 19 19 | 
             
              spec.require_paths = ["lib"]
         | 
| 20 20 |  | 
| 21 | 
            +
              spec.add_dependency "activerecord"
         | 
| 22 | 
            +
             | 
| 21 23 | 
             
              spec.add_development_dependency "bundler", "~> 1.7"
         | 
| 22 24 | 
             
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 23 25 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: order_order
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0 | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - George Millo
         | 
| @@ -10,6 +10,20 @@ bindir: bin | |
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 | 
             
            date: 2014-12-28 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: activerecord
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 13 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 28 | 
             
              name: bundler
         | 
| 15 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -51,6 +65,7 @@ files: | |
| 51 65 | 
             
            - README.md
         | 
| 52 66 | 
             
            - Rakefile
         | 
| 53 67 | 
             
            - lib/order_order.rb
         | 
| 68 | 
            +
            - lib/order_order/extensions.rb
         | 
| 54 69 | 
             
            - lib/order_order/version.rb
         | 
| 55 70 | 
             
            - order_order.gemspec
         | 
| 56 71 | 
             
            homepage: http://github.com/headstock/order_order
         |