sticky_params 2.1.0 → 2.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 +5 -3
- data/lib/sticky_params/base_params.rb +45 -0
- data/lib/sticky_params/session_params.rb +1 -29
- data/lib/sticky_params/strong_session_params.rb +1 -29
- data/lib/sticky_params/version.rb +1 -1
- data/lib/sticky_params.rb +1 -0
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: dd99a57715a3846a6f11b9e4922883177861cececfa89b11c815db6d1723d8f1
         | 
| 4 | 
            +
              data.tar.gz: 2ccceedbeeecd024d6074ea9ba02c2d52b9385983392a11cd23a6f4317275ce5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 163f301446312d74547fb8c31d5cc986ae12a01c611620104c9109a733f33af70e2123e69024a1c7b8312bb30976a87b357791d09e3fe6d05a96784067fb399b
         | 
| 7 | 
            +
              data.tar.gz: 262fe467d410e449540c10605450f3bb0b839ecd73330f0d1fe1b77ae3d4a8dda5e2a4daac0661a709684e151075a65257f34ac7add620ffea637d92cdfe926b
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            # StickyParams
         | 
| 2 2 |  | 
| 3 | 
            -
            A little gem that  | 
| 3 | 
            +
            A little gem that automatically remembers the request parameters between requests without hassle.
         | 
| 4 4 | 
             
            For example for remembering the filtering and sorting of a list, when switching to a detail screen and back.
         | 
| 5 5 |  | 
| 6 6 | 
             
            ```ruby
         | 
| @@ -14,8 +14,10 @@ end | |
| 14 14 |  | 
| 15 15 | 
             
            ## Release Notes 2.1
         | 
| 16 16 |  | 
| 17 | 
            +
            Release 2.1.1, Add the method `with_prefix`, to invoke a block of code with another sticky_params prefix.
         | 
| 18 | 
            +
            It also deduplicates code by moving it to the `StickyParams::BaseParams` class.
         | 
| 17 19 |  | 
| 18 | 
            -
            Release 2.1, Sticky Params doesn't put ActionController::Parameters in a  | 
| 20 | 
            +
            Release 2.1, Sticky Params doesn't put ActionController::Parameters in a session anymore.
         | 
| 19 21 | 
             
            ActionController::Parameters were put directly into a session in 2.0. Which worked in rails < 7.
         | 
| 20 22 | 
             
            In rails 7 this results in a `TypeError (can't dump IO)` when the session data is serialized.
         | 
| 21 23 |  | 
| @@ -23,7 +25,7 @@ Release 2.0, uses ActionController::Parameters instead of hashes. | |
| 23 25 | 
             
            This enable the usage of the strong parameter permit construct.
         | 
| 24 26 | 
             
            (In other words, sticky_params will work just like normal params)
         | 
| 25 27 |  | 
| 26 | 
            -
            To get the 1.0  | 
| 28 | 
            +
            To get the 1.0 behavior, you can add the following to your ApplicationController.
         | 
| 27 29 |  | 
| 28 30 | 
             
            ```ruby
         | 
| 29 31 | 
             
              def sticky_params
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module StickyParams
         | 
| 4 | 
            +
              class BaseParams
         | 
| 5 | 
            +
                attr_reader :controller
         | 
| 6 | 
            +
                attr_accessor :prefix
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(controller)
         | 
| 9 | 
            +
                  @controller = controller
         | 
| 10 | 
            +
                  @prefix = "#{controller.controller_name}_#{controller.action_name}_"
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def []=(name, value)
         | 
| 14 | 
            +
                  session_param_name = "#{prefix}#{name}"
         | 
| 15 | 
            +
                  controller.session['sticky_params'] ||= {}
         | 
| 16 | 
            +
                  controller.session['sticky_params'][session_param_name] = controller.params[name] = value
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                # clears all sticky params for the current controller/action name
         | 
| 20 | 
            +
                def clear!
         | 
| 21 | 
            +
                  if controller.session['sticky_params'].present?
         | 
| 22 | 
            +
                    controller.session['sticky_params'].reject! do |key, _value|
         | 
| 23 | 
            +
                      key.index(prefix) == 0
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                # clears all sticky parameters
         | 
| 29 | 
            +
                def clear_all!
         | 
| 30 | 
            +
                  controller.session.delete('sticky_params')
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                # invokes the given block with another sticky_params prefix
         | 
| 34 | 
            +
                # (accessing other session-params withing the block)
         | 
| 35 | 
            +
                def with_prefix(new_prefix, &)
         | 
| 36 | 
            +
                  old_prefix = prefix
         | 
| 37 | 
            +
                  begin
         | 
| 38 | 
            +
                    self.prefix = new_prefix
         | 
| 39 | 
            +
                    yield self
         | 
| 40 | 
            +
                  ensure
         | 
| 41 | 
            +
                    self.prefix = old_prefix
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -1,13 +1,5 @@ | |
| 1 1 | 
             
            module StickyParams
         | 
| 2 | 
            -
              class SessionParams
         | 
| 3 | 
            -
                attr_reader :controller
         | 
| 4 | 
            -
                attr_accessor :prefix
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                def initialize(controller)
         | 
| 7 | 
            -
                  @controller = controller
         | 
| 8 | 
            -
                  @prefix = "#{controller.controller_name}_#{controller.action_name}_"
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 2 | 
            +
              class SessionParams < BaseParams
         | 
| 11 3 | 
             
                def [](name)
         | 
| 12 4 | 
             
                  session_param_name = "#{prefix}#{name}"
         | 
| 13 5 | 
             
                  controller.session['sticky_params'] ||= {}
         | 
| @@ -22,25 +14,5 @@ module StickyParams | |
| 22 14 | 
             
                    controller.session['sticky_params'][session_param_name]
         | 
| 23 15 | 
             
                  end
         | 
| 24 16 | 
             
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def []=(name, value)
         | 
| 27 | 
            -
                  session_param_name = "#{prefix}#{name}"
         | 
| 28 | 
            -
                  controller.session['sticky_params'] ||= {}
         | 
| 29 | 
            -
                  controller.session['sticky_params'][session_param_name] = controller.params[name] = value
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                # clears all sticky params for the current controller/action name
         | 
| 33 | 
            -
                def clear!
         | 
| 34 | 
            -
                  if controller.session['sticky_params'].present?
         | 
| 35 | 
            -
                    controller.session['sticky_params'].reject! do |key, _value|
         | 
| 36 | 
            -
                      key.index(prefix) == 0
         | 
| 37 | 
            -
                    end
         | 
| 38 | 
            -
                  end
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                # clears all sticky parameters
         | 
| 42 | 
            -
                def clear_all!
         | 
| 43 | 
            -
                  controller.session.delete('sticky_params')
         | 
| 44 | 
            -
                end
         | 
| 45 17 | 
             
              end
         | 
| 46 18 | 
             
            end
         | 
| @@ -1,13 +1,5 @@ | |
| 1 1 | 
             
            module StickyParams
         | 
| 2 | 
            -
              class StrongSessionParams
         | 
| 3 | 
            -
                attr_reader :controller
         | 
| 4 | 
            -
                attr_accessor :prefix
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                def initialize(controller)
         | 
| 7 | 
            -
                  @controller = controller
         | 
| 8 | 
            -
                  @prefix = "#{controller.controller_name}_#{controller.action_name}_"
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 2 | 
            +
              class StrongSessionParams < BaseParams
         | 
| 11 3 | 
             
                def fetch_from_params(name, session_param_name)
         | 
| 12 4 | 
             
                  if controller.params[name].present?
         | 
| 13 5 | 
             
                    if controller.params[name].is_a?(ActionController::Parameters)
         | 
| @@ -37,25 +29,5 @@ module StickyParams | |
| 37 29 | 
             
                    fetch_from_session(session_param_name)
         | 
| 38 30 | 
             
                  end
         | 
| 39 31 | 
             
                end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                def []=(name, value)
         | 
| 42 | 
            -
                  session_param_name = "#{prefix}#{name}"
         | 
| 43 | 
            -
                  controller.session['sticky_params'] ||= {}
         | 
| 44 | 
            -
                  controller.session['sticky_params'][session_param_name] = controller.params[name] = value
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                # clears all sticky params for the current controller/action name
         | 
| 48 | 
            -
                def clear!
         | 
| 49 | 
            -
                  if controller.session['sticky_params'].present?
         | 
| 50 | 
            -
                    controller.session['sticky_params'].reject! do |key, _value|
         | 
| 51 | 
            -
                      key.index(prefix) == 0
         | 
| 52 | 
            -
                    end
         | 
| 53 | 
            -
                  end
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                # clears all sticky parameters
         | 
| 57 | 
            -
                def clear_all!
         | 
| 58 | 
            -
                  controller.session.delete('sticky_params')
         | 
| 59 | 
            -
                end
         | 
| 60 32 | 
             
              end
         | 
| 61 33 | 
             
            end
         | 
    
        data/lib/sticky_params.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sticky_params
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.1. | 
| 4 | 
            +
              version: 2.1.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Rick Blommers
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2023-07-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: A rails gem that automaticly remembers request parameters between requests
         | 
| 14 14 | 
             
            email:
         | 
| @@ -23,6 +23,7 @@ files: | |
| 23 23 | 
             
            - README.md
         | 
| 24 24 | 
             
            - Rakefile
         | 
| 25 25 | 
             
            - lib/sticky_params.rb
         | 
| 26 | 
            +
            - lib/sticky_params/base_params.rb
         | 
| 26 27 | 
             
            - lib/sticky_params/railtie.rb
         | 
| 27 28 | 
             
            - lib/sticky_params/session_params.rb
         | 
| 28 29 | 
             
            - lib/sticky_params/strong_session_params.rb
         | 
| @@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 47 48 | 
             
                - !ruby/object:Gem::Version
         | 
| 48 49 | 
             
                  version: '0'
         | 
| 49 50 | 
             
            requirements: []
         | 
| 50 | 
            -
            rubygems_version: 3. | 
| 51 | 
            +
            rubygems_version: 3.4.15
         | 
| 51 52 | 
             
            signing_key:
         | 
| 52 53 | 
             
            specification_version: 4
         | 
| 53 54 | 
             
            summary: A rails gem that automaticly remembers request parameters between requests
         |