scopie_rails 1.0.1 → 1.1.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/README.md +10 -4
- data/lib/generators/rspec/scopie_generator.rb +11 -0
- data/lib/generators/rspec/templates/scopie_spec.rb +4 -0
- data/lib/generators/scopie_rails/scopie/USAGE +8 -0
- data/lib/generators/scopie_rails/scopie/scopie_generator.rb +13 -0
- data/lib/generators/scopie_rails/scopie/templates/scopie.rb +4 -0
- data/lib/scopie_rails.rb +2 -1
- data/lib/scopie_rails/controller.rb +18 -4
- data/lib/scopie_rails/version.rb +1 -1
- metadata +7 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c74975fde612d205c6c5e0f74b0c4939d6ba0ac6
         | 
| 4 | 
            +
              data.tar.gz: 445d27e9da50cc477811e561fa208ddc991a510b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2ac70de4033ed79c3da88cd517264c7e3831e4732cbbe6561370172f66a967954236819cdfe59d9d8fb7a3f109f46ae54c97b2df669e9fb7da1aad7b0d94d50b
         | 
| 7 | 
            +
              data.tar.gz: fbeb34488d40978aa21100de898ef086aaa7cad144bbdaa27be2fed41c0eddbdad4d34a181fe5f7e8dedabeff6ad579447b36dbcdf6ecfbf1b17580b826de940
         | 
    
        data/README.md
    CHANGED
    
    | @@ -13,8 +13,8 @@ ScopieRails allows you to map incoming controller parameters to named scopes in | |
| 13 13 | 
             
            Motivation:
         | 
| 14 14 |  | 
| 15 15 | 
             
            * Dedicated class for scopes mapping, so that the logic is isolated and your controller is skinny.
         | 
| 16 | 
            -
            * Ability to override default mapping behavior by definition of a method  | 
| 17 | 
            -
            * Ability to DRY your custom scopes mapping logic  | 
| 16 | 
            +
            * Ability to override default mapping behavior by definition of a method having the same name as a scope in the scopie class.
         | 
| 17 | 
            +
            * Ability to use the object oriented approach to DRY your custom scopes mapping logic and reuse the scopie class.
         | 
| 18 18 |  | 
| 19 19 | 
             
            Imagine the following model called graduations:
         | 
| 20 20 |  | 
| @@ -121,6 +121,10 @@ Add `scopie_rails` to your Gemfile or install it from Rubygems. | |
| 121 121 | 
             
            gem 'scopie_rails'
         | 
| 122 122 | 
             
            ```
         | 
| 123 123 |  | 
| 124 | 
            +
            ## Mutation testing
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                mutant --include lib --require scopie_rails --use rspec ScopieRails*
         | 
| 127 | 
            +
             | 
| 124 128 | 
             
            ## Options
         | 
| 125 129 |  | 
| 126 130 | 
             
            Scopie supports several options:
         | 
| @@ -137,17 +141,19 @@ Scopie supports several options: | |
| 137 141 |  | 
| 138 142 | 
             
            * `:allow_blank` - Blank values are not sent to scopes by default. Set to true to overwrite.
         | 
| 139 143 |  | 
| 144 | 
            +
            * `:ignore_blank` - Set to true to not apply the scope if blank value is given.
         | 
| 145 | 
            +
             | 
| 140 146 | 
             
            * `:default` - Default value for the scope. Whenever supplied the scope is always called.
         | 
| 141 147 |  | 
| 142 148 | 
             
            ## Rails
         | 
| 143 149 |  | 
| 144 150 | 
             
            ScopieRails provides Rails integration for [Scopie][s].
         | 
| 145 151 |  | 
| 146 | 
            -
            Among other things it adds a  | 
| 152 | 
            +
            Among other things it adds a `controller` method to scopies.
         | 
| 147 153 |  | 
| 148 154 | 
             
            ## Thanks
         | 
| 149 155 |  | 
| 150 | 
            -
            Scopie was inspired by [has_scope](http://github.com/plataformatec/has_scope) and [pundit](http://github.com/elabs/ | 
| 156 | 
            +
            Scopie was inspired by [has_scope](http://github.com/plataformatec/has_scope) and [pundit](http://github.com/elabs/pundit).
         | 
| 151 157 |  | 
| 152 158 | 
             
            Thanks to both.
         | 
| 153 159 |  | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            module Rspec
         | 
| 2 | 
            +
              module Generators
         | 
| 3 | 
            +
                class ScopieGenerator < ::Rails::Generators::NamedBase
         | 
| 4 | 
            +
                  source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def create_scopie_spec
         | 
| 7 | 
            +
                    template 'scopie_spec.rb', File.join('spec/scopies', class_path, "#{file_name}_scopie_spec.rb")
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            module ScopieRails
         | 
| 2 | 
            +
              module Generators
         | 
| 3 | 
            +
                class ScopieGenerator < ::Rails::Generators::NamedBase
         | 
| 4 | 
            +
                  source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  def create_scopie
         | 
| 7 | 
            +
                    template 'scopie.rb', File.join('app/scopies', class_path, "#{file_name}_scopie.rb")
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  hook_for :test_framework
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
    
        data/lib/scopie_rails.rb
    CHANGED
    
    | @@ -7,8 +7,9 @@ require 'active_support/core_ext/string/inflections' | |
| 7 7 |  | 
| 8 8 | 
             
            module ScopieRails
         | 
| 9 9 |  | 
| 10 | 
            -
              SCOPIE_SUFFIX = '_scopie'
         | 
| 10 | 
            +
              SCOPIE_SUFFIX = '_scopie'.freeze
         | 
| 11 11 |  | 
| 12 | 
            +
              require 'scopie_rails/version'
         | 
| 12 13 | 
             
              require 'scopie_rails/engine' if defined?(Rails)
         | 
| 13 14 | 
             
              require 'scopie_rails/base'
         | 
| 14 15 | 
             
              require 'scopie_rails/controller'
         | 
| @@ -10,21 +10,35 @@ module ScopieRails::Controller | |
| 10 10 | 
             
                @default_scopie ||= find_scopie_class.new(self)
         | 
| 11 11 | 
             
              end
         | 
| 12 12 |  | 
| 13 | 
            +
              # Receives an object where scopes will be applied to.
         | 
| 14 | 
            +
              #
         | 
| 15 | 
            +
              #   class GraduationsScopie < Scopie::Base
         | 
| 16 | 
            +
              #     has_scope :featured, type: :boolean
         | 
| 17 | 
            +
              #     has_scope :by_degree, :by_period
         | 
| 18 | 
            +
              #   end
         | 
| 19 | 
            +
              #
         | 
| 20 | 
            +
              #   class GraduationsController < ApplicationController
         | 
| 21 | 
            +
              #     include ScopieRails::Controller
         | 
| 22 | 
            +
              #
         | 
| 23 | 
            +
              #     def index
         | 
| 24 | 
            +
              #       @graduations = apply_scopes(Graduation).all
         | 
| 25 | 
            +
              #     end
         | 
| 26 | 
            +
              #   end
         | 
| 27 | 
            +
              #
         | 
| 13 28 | 
             
              def apply_scopes(target, scopie: default_scopie, hash: params)
         | 
| 14 29 | 
             
                Scopie.apply_scopes(target, hash, method: hash[:action], scopie: scopie)
         | 
| 15 30 | 
             
              end
         | 
| 16 31 |  | 
| 32 | 
            +
              # Returns the scopes used in this action.
         | 
| 17 33 | 
             
              def current_scopes(scopie: default_scopie, hash: params)
         | 
| 18 34 | 
             
                Scopie.current_scopes(hash, method: hash[:action], scopie: scopie)
         | 
| 19 35 | 
             
              end
         | 
| 20 36 |  | 
| 21 37 | 
             
              def find_scopie_class
         | 
| 22 | 
            -
                return  | 
| 38 | 
            +
                return scopie_class if scopie_class
         | 
| 23 39 |  | 
| 24 40 | 
             
                scopie_name = params[:controller] + ScopieRails::SCOPIE_SUFFIX
         | 
| 25 41 |  | 
| 26 | 
            -
                self. | 
| 27 | 
            -
             | 
| 28 | 
            -
                self.class.scopie_class
         | 
| 42 | 
            +
                self.scopie_class = scopie_name.camelize.constantize
         | 
| 29 43 | 
             
              end
         | 
| 30 44 | 
             
            end
         | 
    
        data/lib/scopie_rails/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: scopie_rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Yury Kotov
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-08-29 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: scopie
         | 
| @@ -73,6 +73,11 @@ extra_rdoc_files: [] | |
| 73 73 | 
             
            files:
         | 
| 74 74 | 
             
            - LICENSE
         | 
| 75 75 | 
             
            - README.md
         | 
| 76 | 
            +
            - lib/generators/rspec/scopie_generator.rb
         | 
| 77 | 
            +
            - lib/generators/rspec/templates/scopie_spec.rb
         | 
| 78 | 
            +
            - lib/generators/scopie_rails/scopie/USAGE
         | 
| 79 | 
            +
            - lib/generators/scopie_rails/scopie/scopie_generator.rb
         | 
| 80 | 
            +
            - lib/generators/scopie_rails/scopie/templates/scopie.rb
         | 
| 76 81 | 
             
            - lib/scopie_rails.rb
         | 
| 77 82 | 
             
            - lib/scopie_rails/base.rb
         | 
| 78 83 | 
             
            - lib/scopie_rails/controller.rb
         |