request_handler 0.9.1 → 0.10.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/.rubocop.yml +4 -1
- data/.travis.yml +31 -5
- data/CHANGELOG.md +8 -0
- data/Dangerfile +26 -0
- data/Gemfile +6 -0
- data/README.md +0 -1
- data/lib/request_handler/base.rb +23 -11
- data/lib/request_handler/body_parser.rb +4 -2
- data/lib/request_handler/fieldsets_parser.rb +2 -2
- data/lib/request_handler/include_option_parser.rb +1 -1
- data/lib/request_handler/page_parser.rb +2 -2
- data/lib/request_handler/schema_parser.rb +1 -1
- data/lib/request_handler/sort_option_parser.rb +1 -1
- data/lib/request_handler/version.rb +1 -1
- data/request_handler.gemspec +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 252b6dd26a2f9989d6bb8782a7cfec3c745db91d
         | 
| 4 | 
            +
              data.tar.gz: 95efc2b338c327105d3bd1e6836c92848d1d51c8
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 348b442311e1f02780bb6e6207534dd00d23a614d443a384240fb1814853df6f996f59cad3eecd463a88763c732a16f4a1621e95a061068b6d058cebfbc56f65
         | 
| 7 | 
            +
              data.tar.gz: 941fd8a4714ff60b793475125b0e74fe2187f669ca603cd2821f8bcbf59fa41191e41a32f3eb9189acbff46ed6bb3f0a4b4c2e6aaa882c50279b189208bd589a
         | 
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -1,11 +1,14 @@ | |
| 1 1 | 
             
            # minitest specifics
         | 
| 2 2 | 
             
            AllCops:
         | 
| 3 | 
            -
              TargetRubyVersion: 2. | 
| 3 | 
            +
              TargetRubyVersion: 2.1
         | 
| 4 4 | 
             
            Metrics/LineLength:
         | 
| 5 5 | 
             
              Max: 119
         | 
| 6 6 | 
             
            Metrics/MethodLength:
         | 
| 7 7 | 
             
              Exclude:
         | 
| 8 8 | 
             
                - test/**/*
         | 
| 9 | 
            +
            Metrics/ClassLength:
         | 
| 10 | 
            +
              Exclude:
         | 
| 11 | 
            +
                - lib/request_handler/base.rb
         | 
| 9 12 | 
             
            Style/ClassAndModuleChildren:
         | 
| 10 13 | 
             
              Exclude:
         | 
| 11 14 | 
             
                - test/**/*
         | 
    
        data/.travis.yml
    CHANGED
    
    | @@ -1,10 +1,36 @@ | |
| 1 | 
            -
            sudo: false
         | 
| 2 1 | 
             
            language: ruby
         | 
| 3 2 | 
             
            cache: bundler
         | 
| 4 | 
            -
            jdk:
         | 
| 5 | 
            -
              - oraclejdk8
         | 
| 6 3 | 
             
            rvm:
         | 
| 4 | 
            +
              - 2.1.10
         | 
| 5 | 
            +
              - 2.2.6
         | 
| 7 6 | 
             
              - 2.3.3
         | 
| 8 7 | 
             
              - 2.4.0
         | 
| 9 | 
            -
              - jruby-9.1. | 
| 10 | 
            -
             | 
| 8 | 
            +
              - jruby-9.1.7.0
         | 
| 9 | 
            +
            jdk:
         | 
| 10 | 
            +
              - oraclejdk8
         | 
| 11 | 
            +
            env:
         | 
| 12 | 
            +
              - "JRUBY_OPTS='--dev --debug'"
         | 
| 13 | 
            +
              - "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 14 | 
            +
            matrix:
         | 
| 15 | 
            +
              exclude:
         | 
| 16 | 
            +
                - rvm: 2.1.10
         | 
| 17 | 
            +
                  jdk: oraclejdk8
         | 
| 18 | 
            +
                  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 19 | 
            +
                - rvm: 2.2.6
         | 
| 20 | 
            +
                  jdk: oraclejdk8
         | 
| 21 | 
            +
                  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 22 | 
            +
                - rvm: 2.3.3
         | 
| 23 | 
            +
                  jdk: oraclejdk8
         | 
| 24 | 
            +
                  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 25 | 
            +
                - rvm: 2.4.0
         | 
| 26 | 
            +
                  jdk: oraclejdk8
         | 
| 27 | 
            +
                  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 28 | 
            +
              allow_failures:
         | 
| 29 | 
            +
                - rvm: jruby-9.1.7.0
         | 
| 30 | 
            +
                  jdk: oraclejdk8
         | 
| 31 | 
            +
                  env: "JRUBY_OPTS='-Xcompile.invokedynamic=true --debug'"
         | 
| 32 | 
            +
            before_install:
         | 
| 33 | 
            +
              - gem update --system
         | 
| 34 | 
            +
              - gem install bundler -v 1.13.6
         | 
| 35 | 
            +
            before_script:
         | 
| 36 | 
            +
              - bundle exec danger
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -3,6 +3,14 @@ Changelog | |
| 3 3 |  | 
| 4 4 | 
             
            ## master
         | 
| 5 5 |  | 
| 6 | 
            +
            ## 0.10.0
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            - raise an error if mandatory options are missing in the handler configuration
         | 
| 9 | 
            +
            - Transform param keys to string before substitution
         | 
| 10 | 
            +
            - make gem compatible with ruby 2.1
         | 
| 11 | 
            +
            - add danger
         | 
| 12 | 
            +
            - raise an ExternalArgumentError if the body does not contain data
         | 
| 13 | 
            +
             | 
| 6 14 | 
             
            ## 0.9.1
         | 
| 7 15 |  | 
| 8 16 | 
             
            - fix configure method
         | 
    
        data/Dangerfile
    ADDED
    
    | @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # --------------------------------------------------------------------------------------------------------------------
         | 
| 2 | 
            +
            # Has any changes happened inside the actual library code?
         | 
| 3 | 
            +
            # --------------------------------------------------------------------------------------------------------------------
         | 
| 4 | 
            +
            has_app_changes = !git.modified_files.grep(/lib/).empty?
         | 
| 5 | 
            +
            has_test_changes = !git.modified_files.grep(/spec/).empty?
         | 
| 6 | 
            +
            is_version_bump = git.modified_files.sort == ["CHANGELOG.md", "lib/request_handler/version.rb"].sort
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            if has_app_changes && !has_test_changes && !is_version_bump
         | 
| 9 | 
            +
              warn("Tests were not updated. That's OK if you're refactoring existing code.", sticky: false)
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            if !git.modified_files.include?("CHANGELOG.md") && has_app_changes
         | 
| 13 | 
            +
              fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/request_handler/request_handler/blob/master/CHANGELOG.md).")
         | 
| 14 | 
            +
              message "Note, we hard-wrap at 80 chars and use 2 spaces after the last line."
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            # Make it more obvious that a PR is a work in progress and shouldn't be merged yet
         | 
| 18 | 
            +
            warn("PR is classed as Work in Progress") if github.pr_title.include? "WIP"
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            # Warn when there is a big PR
         | 
| 21 | 
            +
            warn("Big PR") if git.lines_of_code > 500
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            commit_lint.check warn: :all, disable: [:subject_cap]
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            # rubocop
         | 
| 26 | 
            +
            rubocop.lint "*"
         | 
    
        data/Gemfile
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -2,7 +2,6 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            [](https://badge.fury.io/rb/request_handler)
         | 
| 4 4 | 
             
            [](https://travis-ci.org/runtastic/request_handler)
         | 
| 5 | 
            -
            [](https://codeclimate.com/github/runtastic/request_handler)
         | 
| 6 5 | 
             
            [](https://codecov.io/gh/runtastic/request_handler)
         | 
| 7 6 |  | 
| 8 7 | 
             
            This gem allows easy and dry handling of requests based on the dry-validation
         | 
    
        data/lib/request_handler/base.rb
    CHANGED
    
    | @@ -35,7 +35,7 @@ module RequestHandler | |
| 35 35 | 
             
                def page_params
         | 
| 36 36 | 
             
                  @page_params ||= PageParser.new(
         | 
| 37 37 | 
             
                    params:      params,
         | 
| 38 | 
            -
                    page_config:  | 
| 38 | 
            +
                    page_config: lookup!('page')
         | 
| 39 39 | 
             
                  ).run
         | 
| 40 40 | 
             
                end
         | 
| 41 41 |  | 
| @@ -71,9 +71,9 @@ module RequestHandler | |
| 71 71 | 
             
                  defaults = fetch_defaults('filter.defaults', {})
         | 
| 72 72 | 
             
                  defaults.merge(FilterParser.new(
         | 
| 73 73 | 
             
                    params:                params,
         | 
| 74 | 
            -
                    schema:                 | 
| 75 | 
            -
                    additional_url_filter:  | 
| 76 | 
            -
                    schema_options:        execute_options( | 
| 74 | 
            +
                    schema:                lookup!('filter.schema'),
         | 
| 75 | 
            +
                    additional_url_filter: lookup('filter.additional_url_filter'),
         | 
| 76 | 
            +
                    schema_options:        execute_options(lookup('filter.options'))
         | 
| 77 77 | 
             
                  ).run)
         | 
| 78 78 | 
             
                end
         | 
| 79 79 |  | 
| @@ -89,7 +89,7 @@ module RequestHandler | |
| 89 89 | 
             
                  defaults = fetch_defaults("#{type}.defaults", [])
         | 
| 90 90 | 
             
                  result = parser.new(
         | 
| 91 91 | 
             
                    params:               params,
         | 
| 92 | 
            -
                    allowed_options_type:  | 
| 92 | 
            +
                    allowed_options_type: lookup!("#{type}.allowed")
         | 
| 93 93 | 
             
                  ).run
         | 
| 94 94 | 
             
                  result.empty? ? defaults : result
         | 
| 95 95 | 
             
                end
         | 
| @@ -98,19 +98,19 @@ module RequestHandler | |
| 98 98 | 
             
                  defaults = fetch_defaults('body.defaults', {})
         | 
| 99 99 | 
             
                  defaults.merge(BodyParser.new(
         | 
| 100 100 | 
             
                    request:        request,
         | 
| 101 | 
            -
                    schema:          | 
| 102 | 
            -
                    schema_options: execute_options( | 
| 101 | 
            +
                    schema:         lookup!('body.schema'),
         | 
| 102 | 
            +
                    schema_options: execute_options(lookup('body.options'))
         | 
| 103 103 | 
             
                  ).run)
         | 
| 104 104 | 
             
                end
         | 
| 105 105 |  | 
| 106 106 | 
             
                def parse_fieldsets_params
         | 
| 107 107 | 
             
                  FieldsetsParser.new(params:   params,
         | 
| 108 | 
            -
                                      allowed:   | 
| 109 | 
            -
                                      required:  | 
| 108 | 
            +
                                      allowed:  lookup!('fieldsets.allowed'),
         | 
| 109 | 
            +
                                      required: lookup!('fieldsets.required')).run
         | 
| 110 110 | 
             
                end
         | 
| 111 111 |  | 
| 112 112 | 
             
                def fetch_defaults(key, default)
         | 
| 113 | 
            -
                  value =  | 
| 113 | 
            +
                  value = lookup(key)
         | 
| 114 114 | 
             
                  return default if value.nil?
         | 
| 115 115 | 
             
                  return value unless value.respond_to?(:call)
         | 
| 116 116 | 
             
                  value.call(request)
         | 
| @@ -122,10 +122,22 @@ module RequestHandler | |
| 122 122 | 
             
                  options.call(self, request)
         | 
| 123 123 | 
             
                end
         | 
| 124 124 |  | 
| 125 | 
            +
                def lookup!(key)
         | 
| 126 | 
            +
                  config.lookup!(key).tap do |data|
         | 
| 127 | 
            +
                    raise NoConfigAvailableError, key.to_sym => 'is not configured' if data.nil?
         | 
| 128 | 
            +
                  end
         | 
| 129 | 
            +
                end
         | 
| 130 | 
            +
             | 
| 131 | 
            +
                def lookup(key)
         | 
| 132 | 
            +
                  config.lookup!(key)
         | 
| 133 | 
            +
                end
         | 
| 134 | 
            +
             | 
| 125 135 | 
             
                def params
         | 
| 126 136 | 
             
                  raise MissingArgumentError, params: 'is missing' if request.params.nil?
         | 
| 127 137 | 
             
                  raise ExternalArgumentError, params: 'must be a Hash' unless request.params.is_a?(Hash)
         | 
| 128 | 
            -
                  @params ||= Helper.deep_transform_keys_in_object(request.params)  | 
| 138 | 
            +
                  @params ||= Helper.deep_transform_keys_in_object(request.params) do |k|
         | 
| 139 | 
            +
                    k.to_s.gsub('.', ::RequestHandler.separator)
         | 
| 140 | 
            +
                  end
         | 
| 129 141 | 
             
                end
         | 
| 130 142 |  | 
| 131 143 | 
             
                def config
         | 
| @@ -4,7 +4,7 @@ require 'request_handler/error' | |
| 4 4 | 
             
            module RequestHandler
         | 
| 5 5 | 
             
              class BodyParser < SchemaParser
         | 
| 6 6 | 
             
                def initialize(request:, schema:, schema_options: {})
         | 
| 7 | 
            -
                  raise MissingArgumentError, "request.body" | 
| 7 | 
            +
                  raise MissingArgumentError, :"request.body" => 'is missing' if request.body.nil?
         | 
| 8 8 | 
             
                  super(schema: schema, schema_options: schema_options)
         | 
| 9 9 | 
             
                  @request = request
         | 
| 10 10 | 
             
                end
         | 
| @@ -16,7 +16,9 @@ module RequestHandler | |
| 16 16 | 
             
                private
         | 
| 17 17 |  | 
| 18 18 | 
             
                def flattened_request_body
         | 
| 19 | 
            -
                  body = request_body | 
| 19 | 
            +
                  body = request_body.fetch('data') do
         | 
| 20 | 
            +
                    raise ExternalArgumentError, body: 'must contain data'
         | 
| 21 | 
            +
                  end
         | 
| 20 22 | 
             
                  body.merge!(body.delete('attributes') { {} })
         | 
| 21 23 | 
             
                  relationships = flatten_relationship_resource_linkages(body.delete('relationships') { {} })
         | 
| 22 24 | 
             
                  body.merge!(relationships)
         | 
| @@ -45,12 +45,12 @@ module RequestHandler | |
| 45 45 | 
             
                end
         | 
| 46 46 |  | 
| 47 47 | 
             
                def raise_invalid_field_option(type)
         | 
| 48 | 
            -
                  return if allowed | 
| 48 | 
            +
                  return if allowed.key?(type)
         | 
| 49 49 | 
             
                  raise OptionNotAllowedError, fieldsets: "fieldsets for type: #{type} not allowed"
         | 
| 50 50 | 
             
                end
         | 
| 51 51 |  | 
| 52 52 | 
             
                def raise_missing_fields_param
         | 
| 53 | 
            -
                  return if required. | 
| 53 | 
            +
                  return if required.empty?
         | 
| 54 54 | 
             
                  raise ExternalArgumentError, fieldsets: 'missing required fields options'
         | 
| 55 55 | 
             
                end
         | 
| 56 56 |  | 
| @@ -14,7 +14,7 @@ module RequestHandler | |
| 14 14 | 
             
                  options.map do |option|
         | 
| 15 15 | 
             
                    option.gsub!('.', ::RequestHandler.separator)
         | 
| 16 16 | 
             
                    begin
         | 
| 17 | 
            -
                      allowed_options_type | 
| 17 | 
            +
                      allowed_options_type.call(option).to_sym
         | 
| 18 18 | 
             
                    rescue Dry::Types::ConstraintError
         | 
| 19 19 | 
             
                      raise OptionNotAllowedError, option.to_sym => 'is not an allowed include option'
         | 
| 20 20 | 
             
                    end
         | 
| @@ -51,7 +51,7 @@ module RequestHandler | |
| 51 51 | 
             
                def fetch_and_check_default_size(prefix)
         | 
| 52 52 | 
             
                  default_size = lookup_nested_config_key('default_size', prefix)
         | 
| 53 53 | 
             
                  raise_no_default_size(prefix) if default_size.nil?
         | 
| 54 | 
            -
                  raise_not_positive(prefix, 'size') unless default_size.is_a?(Integer) && default_size | 
| 54 | 
            +
                  raise_not_positive(prefix, 'size') unless default_size.is_a?(Integer) && default_size > 0
         | 
| 55 55 | 
             
                  default_size
         | 
| 56 56 | 
             
                end
         | 
| 57 57 |  | 
| @@ -64,7 +64,7 @@ module RequestHandler | |
| 64 64 |  | 
| 65 65 | 
             
                def check_int(string:, error_msg:)
         | 
| 66 66 | 
             
                  output = Integer(string)
         | 
| 67 | 
            -
                  raise ExternalArgumentError, error_msg unless output | 
| 67 | 
            +
                  raise ExternalArgumentError, error_msg unless output > 0
         | 
| 68 68 | 
             
                  output
         | 
| 69 69 | 
             
                rescue ArgumentError
         | 
| 70 70 | 
             
                  raise ExternalArgumentError, error_msg
         | 
| @@ -6,7 +6,7 @@ module RequestHandler | |
| 6 6 | 
             
                  missing_arguments = []
         | 
| 7 7 | 
             
                  missing_arguments << { schema: 'is missing' } if schema.nil?
         | 
| 8 8 | 
             
                  missing_arguments << { schema_options: 'is missing' } if schema_options.nil?
         | 
| 9 | 
            -
                  raise MissingArgumentError, missing_arguments  | 
| 9 | 
            +
                  raise MissingArgumentError, missing_arguments unless missing_arguments.empty?
         | 
| 10 10 | 
             
                  raise InternalArgumentError, schema: 'must be a Schema' unless schema.is_a?(Dry::Validation::Schema)
         | 
| 11 11 | 
             
                  @schema = schema
         | 
| 12 12 | 
             
                  @schema_options = schema_options
         | 
    
        data/request_handler.gemspec
    CHANGED
    
    | @@ -15,7 +15,7 @@ Gem::Specification.new do |spec| | |
| 15 15 | 
             
              spec.description   = 'shared base for request_handler using dry-* gems'
         | 
| 16 16 | 
             
              spec.homepage      = 'https://github.com/runtastic/request_handler'
         | 
| 17 17 | 
             
              spec.license       = 'MIT'
         | 
| 18 | 
            -
              spec.required_ruby_version = '~> 2. | 
| 18 | 
            +
              spec.required_ruby_version = '~> 2.1'
         | 
| 19 19 |  | 
| 20 20 | 
             
              spec.files = `git ls-files -z`.split("\x0").reject do |f|
         | 
| 21 21 | 
             
                f.match(%r{^(test|spec|features)/})
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: request_handler
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Andreas Eger
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: exe
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2017- | 
| 12 | 
            +
            date: 2017-02-16 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: dry-validation
         | 
| @@ -220,6 +220,7 @@ files: | |
| 220 220 | 
             
            - ".rubocop.yml"
         | 
| 221 221 | 
             
            - ".travis.yml"
         | 
| 222 222 | 
             
            - CHANGELOG.md
         | 
| 223 | 
            +
            - Dangerfile
         | 
| 223 224 | 
             
            - Gemfile
         | 
| 224 225 | 
             
            - Guardfile
         | 
| 225 226 | 
             
            - LICENSE.txt
         | 
| @@ -256,7 +257,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 256 257 | 
             
              requirements:
         | 
| 257 258 | 
             
              - - "~>"
         | 
| 258 259 | 
             
                - !ruby/object:Gem::Version
         | 
| 259 | 
            -
                  version: '2. | 
| 260 | 
            +
                  version: '2.1'
         | 
| 260 261 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 261 262 | 
             
              requirements:
         | 
| 262 263 | 
             
              - - ">="
         |