filterameter 0.8.0 → 0.9.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/README.md +34 -10
- data/lib/filterameter/configuration.rb +14 -1
- data/lib/filterameter/declarative_filters.rb +7 -1
- data/lib/filterameter/filter_coordinator.rb +1 -1
- data/lib/filterameter/log_subscriber.rb +2 -2
- data/lib/filterameter/registries/filter_registry.rb +4 -0
- data/lib/filterameter/registries/registry.rb +1 -1
- data/lib/filterameter/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: f62d4fc49f10adca7c1fec20fb17e430740035d69b154f973d8f300405f64f9c
         | 
| 4 | 
            +
              data.tar.gz: 7369430dbb71a29faf17853a35eaa69f3a35fae52b82d63e85f5c14bd550aa51
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e5ee234ae90460282e2618135b96f91882af00361b1c16eda99beb42640cf9c4186d1bb61fa1989235015a1f4dff07f7611ca5dea55ec6277c27dc9239329bc8
         | 
| 7 | 
            +
              data.tar.gz: 6f802f89428a06de2f077d5c4b38464bc8ad1ee4327d334856f3421481cba3af84ef789cb2e85863fe933f8b45f90fe2b7640910d16618bb97e35c65d9bda691
         | 
    
        data/README.md
    CHANGED
    
    | @@ -200,6 +200,7 @@ Rails conventions are used to determine the controller's model. For example, the | |
| 200 200 | 
             
            filter_model 'Picture'
         | 
| 201 201 | 
             
            ```
         | 
| 202 202 |  | 
| 203 | 
            +
            _Important:_ If the `filter_model` declaration is used, it must be before any filter or sort declarations.
         | 
| 203 204 |  | 
| 204 205 | 
             
            ### Building the Query
         | 
| 205 206 |  | 
| @@ -299,25 +300,48 @@ For example, the following sorts by size descending: | |
| 299 300 |  | 
| 300 301 | 
             
            `/widgets?filter[sort]=-size`
         | 
| 301 302 |  | 
| 303 | 
            +
            ### Configuration
         | 
| 302 304 |  | 
| 303 | 
            -
             | 
| 305 | 
            +
            There are three configuration options:
         | 
| 304 306 |  | 
| 305 | 
            -
             | 
| 307 | 
            +
            - action_on_undeclared_parameters
         | 
| 308 | 
            +
            - action_on_validation_failure
         | 
| 309 | 
            +
            - filter_key
         | 
| 306 310 |  | 
| 307 | 
            -
             | 
| 308 | 
            -
             | 
| 309 | 
            -
             | 
| 310 | 
            -
            end
         | 
| 311 | 
            -
            ```
         | 
| 311 | 
            +
            The configuration options can be set in an initializer, an environment file, or in `application.rb`. 
         | 
| 312 | 
            +
             | 
| 313 | 
            +
            The options can be set directly...
         | 
| 312 314 |  | 
| 313 | 
            -
             | 
| 315 | 
            +
            `Filterameter.configuration.action_on_undeclared_parameters = :log`
         | 
| 316 | 
            +
             | 
| 317 | 
            +
            ...or the configuration can be yielded:
         | 
| 314 318 |  | 
| 315 319 | 
             
            ```ruby
         | 
| 316 | 
            -
             | 
| 317 | 
            -
               | 
| 320 | 
            +
            Filterameter.configure do |config|
         | 
| 321 | 
            +
              config.action_on_undeclared_parameters = :log
         | 
| 322 | 
            +
              config.action_on_validation_failuer = :log
         | 
| 323 | 
            +
              config.filter_key = :f
         | 
| 318 324 | 
             
            end
         | 
| 319 325 | 
             
            ```
         | 
| 320 326 |  | 
| 327 | 
            +
            #### Action On Undeclared Parameters
         | 
| 328 | 
            +
             | 
| 329 | 
            +
            Occurs when the filter parameter contains any keys that are not defined. Valid actions are `:log`, `:raise`, and `false` (do not take action). By default, development will log, test will raise, and production will do nothing.
         | 
| 330 | 
            +
             | 
| 331 | 
            +
            #### Action on Validation Failure
         | 
| 332 | 
            +
             | 
| 333 | 
            +
            Occurs when a filter parameter fails a validation. Valid actions are `:log`, `:raise`, and `false` (do not take action). By default, development will log, test will raise, and production will do nothing.
         | 
| 334 | 
            +
             | 
| 335 | 
            +
            #### Filter Key
         | 
| 336 | 
            +
             | 
| 337 | 
            +
            By default, the filter parameters are nested under the key `:filter`. Use this setting to override the key.
         | 
| 338 | 
            +
             | 
| 339 | 
            +
            If the filter parameters are NOT nested, set this to false. Doing so will restrict the filter parameters to only
         | 
| 340 | 
            +
            those that have been declared, meaning undeclared parameters are ignored (and the action_on_undeclared_parameters
         | 
| 341 | 
            +
            configuration option does not come into play).
         | 
| 342 | 
            +
             | 
| 343 | 
            +
             | 
| 344 | 
            +
             | 
| 321 345 |  | 
| 322 346 | 
             
            ## Installation
         | 
| 323 347 | 
             
            Add this line to your application's Gemfile:
         | 
| @@ -6,16 +6,27 @@ module Filterameter | |
| 6 6 | 
             
              # Class Configuration stores the following settings:
         | 
| 7 7 | 
             
              # - action_on_undeclared_parameters
         | 
| 8 8 | 
             
              # - action_on_validation_failure
         | 
| 9 | 
            +
              # - filter_key
         | 
| 9 10 | 
             
              #
         | 
| 10 11 | 
             
              # == Action on Undeclared Parameters
         | 
| 12 | 
            +
              #
         | 
| 11 13 | 
             
              # Occurs when the filter parameter contains any keys that are not defined. Valid actions are :log, :raise, and
         | 
| 12 14 | 
             
              # false (do not take action). By default, development will log, test will raise, and production will do nothing.
         | 
| 13 15 | 
             
              #
         | 
| 14 16 | 
             
              # == Action on Validation Failure
         | 
| 17 | 
            +
              #
         | 
| 15 18 | 
             
              # Occurs when a filter parameter fails a validation. Valid actions are :log, :raise, and false (do not take action).
         | 
| 16 19 | 
             
              # By default, development will log, test will raise, and production will do nothing.
         | 
| 20 | 
            +
              #
         | 
| 21 | 
            +
              # == Filter Key
         | 
| 22 | 
            +
              #
         | 
| 23 | 
            +
              # By default, the filter parameters are nested under the key :filter. Use this setting to override the key.
         | 
| 24 | 
            +
              #
         | 
| 25 | 
            +
              # If the filter parameters are NOT nested, set this to false. Doing so will restrict the filter parameters to only
         | 
| 26 | 
            +
              # those that have been declared, meaning undeclared parameters are ignored (and the action_on_undeclared_parameters
         | 
| 27 | 
            +
              # configuration option does not come into play).
         | 
| 17 28 | 
             
              class Configuration
         | 
| 18 | 
            -
                attr_accessor :action_on_undeclared_parameters, :action_on_validation_failure
         | 
| 29 | 
            +
                attr_accessor :action_on_undeclared_parameters, :action_on_validation_failure, :filter_key
         | 
| 19 30 |  | 
| 20 31 | 
             
                def initialize
         | 
| 21 32 | 
             
                  @action_on_undeclared_parameters =
         | 
| @@ -27,6 +38,8 @@ module Filterameter | |
| 27 38 | 
             
                      else
         | 
| 28 39 | 
             
                        false
         | 
| 29 40 | 
             
                      end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  @filter_key = :filter
         | 
| 30 43 | 
             
                end
         | 
| 31 44 | 
             
              end
         | 
| 32 45 | 
             
            end
         | 
| @@ -29,7 +29,13 @@ module Filterameter | |
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| 31 31 | 
             
                def filter_parameters
         | 
| 32 | 
            -
                   | 
| 32 | 
            +
                  filter_key = Filterameter.configuration.filter_key
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  if filter_key
         | 
| 35 | 
            +
                    params.to_unsafe_h.fetch(filter_key, {})
         | 
| 36 | 
            +
                  else
         | 
| 37 | 
            +
                    params.to_unsafe_h.slice(*self.class.filter_coordinator.filter_parameter_names, :sort)
         | 
| 38 | 
            +
                  end
         | 
| 33 39 | 
             
                end
         | 
| 34 40 |  | 
| 35 41 | 
             
                private
         | 
| @@ -19,7 +19,7 @@ module Filterameter | |
| 19 19 | 
             
              class FilterCoordinator
         | 
| 20 20 | 
             
                attr_writer :query_variable_name
         | 
| 21 21 |  | 
| 22 | 
            -
                delegate :add_filter, :add_sort, to: :registry
         | 
| 22 | 
            +
                delegate :add_filter, :add_sort, :filter_parameter_names, to: :registry
         | 
| 23 23 | 
             
                delegate :build_query, to: :query_builder
         | 
| 24 24 |  | 
| 25 25 | 
             
                def initialize(controller_name, controller_path)
         | 
| @@ -14,8 +14,8 @@ module Filterameter | |
| 14 14 |  | 
| 15 15 | 
             
                def undeclared_parameters(event)
         | 
| 16 16 | 
             
                  debug do
         | 
| 17 | 
            -
                     | 
| 18 | 
            -
                    "  Undeclared filter parameter | 
| 17 | 
            +
                    key = event.payload[:key]
         | 
| 18 | 
            +
                    "  Undeclared filter parameter: #{key}"
         | 
| 19 19 | 
             
                  end
         | 
| 20 20 | 
             
                end
         | 
| 21 21 | 
             
              end
         | 
| @@ -6,7 +6,7 @@ module Filterameter | |
| 6 6 | 
             
                #
         | 
| 7 7 | 
             
                # Class Registry records declarations and allows resulting filters and sorts to be fetched from sub-registries.
         | 
| 8 8 | 
             
                class Registry
         | 
| 9 | 
            -
                  delegate :filter_declarations, :ranges, to: :@filter_registry
         | 
| 9 | 
            +
                  delegate :filter_declarations, :filter_parameter_names, :ranges, to: :@filter_registry
         | 
| 10 10 |  | 
| 11 11 | 
             
                  def initialize(model_class)
         | 
| 12 12 | 
             
                    @filter_registry = Filterameter::Registries::FilterRegistry.new(Filterameter::FilterFactory.new(model_class))
         | 
    
        data/lib/filterameter/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: filterameter
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.9.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Todd Kummer
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-07- | 
| 11 | 
            +
            date: 2024-07-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |