scim-kit 0.2.15 → 0.2.16
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 +6 -0
 - data/CHANGELOG.md +42 -0
 - data/bin/test +8 -4
 - data/lib/scim/kit.rb +10 -0
 - data/lib/scim/kit/v2.rb +2 -0
 - data/lib/scim/kit/v2/attributable.rb +11 -6
 - data/lib/scim/kit/v2/attribute.rb +28 -2
 - data/lib/scim/kit/v2/attribute_type.rb +9 -4
 - data/lib/scim/kit/v2/complex_attribute_validator.rb +44 -0
 - data/lib/scim/kit/v2/resource.rb +1 -1
 - data/lib/scim/kit/v2/unknown_attribute.rb +30 -0
 - data/lib/scim/kit/version.rb +1 -1
 - metadata +5 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 888e429b11091880152b63a98fffb2606b91d9b2fa318295ba4fff4e6cf5ab5f
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e4a53aabe13796a5f5eedd50971a3b5b9fcc01c6f8e5508b3be6590ce5dacec6
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 810fce60e3daae9fe523b5162030a56aa42d446b86c881e30dbc02782392371f08cce1023c37fa065e62cc88e3817a435f07efb280c372a700d0c4f21fdd79db
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0f232783f9f5f37d01032827ce7c619529417e8571759363698107ea03fd61182c409520edd171296d2dcea232fce8987aba7cc2d8ed3ba5cb7a373dc2f7f31e
         
     | 
    
        data/.rubocop.yml
    CHANGED
    
    | 
         @@ -9,6 +9,9 @@ AllCops: 
     | 
|
| 
       9 
9 
     | 
    
         
             
                - 'vendor/**/*'
         
     | 
| 
       10 
10 
     | 
    
         
             
              TargetRubyVersion: 2.5
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
      
 12 
     | 
    
         
            +
            Layout/IndentArray:
         
     | 
| 
      
 13 
     | 
    
         
            +
              EnforcedStyle: consistent
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
       12 
15 
     | 
    
         
             
            Metrics/BlockLength:
         
     | 
| 
       13 
16 
     | 
    
         
             
              Exclude:
         
     | 
| 
       14 
17 
     | 
    
         
             
                - '*.gemspec'
         
     | 
| 
         @@ -24,3 +27,6 @@ Naming/FileName: 
     | 
|
| 
       24 
27 
     | 
    
         | 
| 
       25 
28 
     | 
    
         
             
            RSpec/NamedSubject:
         
     | 
| 
       26 
29 
     | 
    
         
             
              Enabled: false
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            RSpec/NestedGroups:
         
     | 
| 
      
 32 
     | 
    
         
            +
              Max: 4
         
     | 
    
        data/CHANGELOG.md
    ADDED
    
    | 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Version 0.2.16
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Changelog
         
     | 
| 
      
 3 
     | 
    
         
            +
            All notable changes to this project will be documented in this file.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
         
     | 
| 
      
 6 
     | 
    
         
            +
            and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            ## [Unreleased]
         
     | 
| 
      
 9 
     | 
    
         
            +
            ### Changed
         
     | 
| 
      
 10 
     | 
    
         
            +
            - nil
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## [0.2.16] - 2019-02-03
         
     | 
| 
      
 13 
     | 
    
         
            +
            ### Added
         
     | 
| 
      
 14 
     | 
    
         
            +
            - Default logger
         
     | 
| 
      
 15 
     | 
    
         
            +
            - Attributes now implement Enumerable
         
     | 
| 
      
 16 
     | 
    
         
            +
            - Attributable#attribute\_for now returns a null object instead of nil.
         
     | 
| 
      
 17 
     | 
    
         
            +
            - Validations for multi valued attributes
         
     | 
| 
      
 18 
     | 
    
         
            +
            - Validations for complex attributes
         
     | 
| 
      
 19 
     | 
    
         
            +
            - rescue errors from type coercion.
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ### Changed
         
     | 
| 
      
 22 
     | 
    
         
            +
            - \_assign does not coerce values by default.
         
     | 
| 
      
 23 
     | 
    
         
            +
            - errors are merged together instead of overwritten during attribute validation.
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            [Unreleased]: https://github.com/mokhan/scim-kit/compare/v0.2.16...HEAD
         
     | 
| 
      
 26 
     | 
    
         
            +
            [0.2.16]: https://github.com/mokhan/scim-kit/compare/v0.2.15...v0.2.16
         
     | 
| 
      
 27 
     | 
    
         
            +
            [0.2.15]: https://github.com/mokhan/scim-kit/compare/v0.2.14...v0.2.15
         
     | 
| 
      
 28 
     | 
    
         
            +
            [0.2.14]: https://github.com/mokhan/scim-kit/compare/v0.2.13...v0.2.14
         
     | 
| 
      
 29 
     | 
    
         
            +
            [0.2.13]: https://github.com/mokhan/scim-kit/compare/v0.2.12...v0.2.13
         
     | 
| 
      
 30 
     | 
    
         
            +
            [0.2.12]: https://github.com/mokhan/scim-kit/compare/v0.2.11...v0.2.12
         
     | 
| 
      
 31 
     | 
    
         
            +
            [0.2.11]: https://github.com/mokhan/scim-kit/compare/v0.2.10...v0.2.11
         
     | 
| 
      
 32 
     | 
    
         
            +
            [0.2.10]: https://github.com/mokhan/scim-kit/compare/v0.2.9...v0.2.10
         
     | 
| 
      
 33 
     | 
    
         
            +
            [0.2.9]: https://github.com/mokhan/scim-kit/compare/v0.2.8...v0.2.9
         
     | 
| 
      
 34 
     | 
    
         
            +
            [0.2.8]: https://github.com/mokhan/scim-kit/compare/v0.2.7...v0.2.8
         
     | 
| 
      
 35 
     | 
    
         
            +
            [0.2.7]: https://github.com/mokhan/scim-kit/compare/v0.2.6...v0.2.7
         
     | 
| 
      
 36 
     | 
    
         
            +
            [0.2.6]: https://github.com/mokhan/scim-kit/compare/v0.2.5...v0.2.6
         
     | 
| 
      
 37 
     | 
    
         
            +
            [0.2.5]: https://github.com/mokhan/scim-kit/compare/v0.2.4...v0.2.5
         
     | 
| 
      
 38 
     | 
    
         
            +
            [0.2.4]: https://github.com/mokhan/scim-kit/compare/v0.2.3...v0.2.4
         
     | 
| 
      
 39 
     | 
    
         
            +
            [0.2.3]: https://github.com/mokhan/scim-kit/compare/v0.2.2...v0.2.3
         
     | 
| 
      
 40 
     | 
    
         
            +
            [0.2.2]: https://github.com/mokhan/scim-kit/compare/v0.2.1...v0.2.2
         
     | 
| 
      
 41 
     | 
    
         
            +
            [0.2.1]: https://github.com/mokhan/scim-kit/compare/v0.2.0...v0.2.1
         
     | 
| 
      
 42 
     | 
    
         
            +
            [0.2.0]: https://github.com/mokhan/scim-kit/compare/v0.1.0...v0.2.0
         
     | 
    
        data/bin/test
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #!/bin/ 
     | 
| 
      
 1 
     | 
    
         
            +
            #!/bin/bash
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # script/test: Run test suite for application. Optionally pass in a path to an
         
     | 
| 
       4 
4 
     | 
    
         
             
            #              individual test file to run a single test.
         
     | 
| 
         @@ -10,8 +10,12 @@ cd "$(dirname "$0")/.." 
     | 
|
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            [ -z "$DEBUG" ] || set -x
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            echo [$(date "+%H:%M:%S")] "==> Running setup…"
         
     | 
| 
      
 13 
     | 
    
         
            +
            echo ["$(date "+%H:%M:%S")"] "==> Running setup…"
         
     | 
| 
       14 
14 
     | 
    
         
             
            bin/setup
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
            echo [$(date "+%H:%M:%S")] "==> Running tests…"
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
            echo ["$(date "+%H:%M:%S")"] "==> Running tests…"
         
     | 
| 
      
 17 
     | 
    
         
            +
            if [[ $# -eq 0 ]]; then
         
     | 
| 
      
 18 
     | 
    
         
            +
              bundle exec rake spec
         
     | 
| 
      
 19 
     | 
    
         
            +
            else
         
     | 
| 
      
 20 
     | 
    
         
            +
              bundle exec rspec "$1"
         
     | 
| 
      
 21 
     | 
    
         
            +
            fi
         
     | 
    
        data/lib/scim/kit.rb
    CHANGED
    
    | 
         @@ -3,6 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'active_model'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'active_support/core_ext/hash/indifferent_access'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'json'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'logger'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'pathname'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'tilt'
         
     | 
| 
       8 
9 
     | 
    
         
             
            require 'tilt/jbuilder'
         
     | 
| 
         @@ -14,8 +15,17 @@ require 'scim/kit/v2' 
     | 
|
| 
       14 
15 
     | 
    
         
             
            require 'scim/kit/version'
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
            module Scim
         
     | 
| 
      
 18 
     | 
    
         
            +
              # @api
         
     | 
| 
       17 
19 
     | 
    
         
             
              module Kit
         
     | 
| 
       18 
20 
     | 
    
         
             
                class Error < StandardError; end
         
     | 
| 
       19 
21 
     | 
    
         
             
                class UnknownAttributeError < Error; end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def self.logger
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @logger ||= Logger.new(STDOUT)
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def self.logger=(logger)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @logger = logger
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
       20 
30 
     | 
    
         
             
              end
         
     | 
| 
       21 
31 
     | 
    
         
             
            end
         
     | 
    
        data/lib/scim/kit/v2.rb
    CHANGED
    
    | 
         @@ -4,6 +4,7 @@ require 'scim/kit/v2/attributable' 
     | 
|
| 
       4 
4 
     | 
    
         
             
            require 'scim/kit/v2/attribute'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require 'scim/kit/v2/attribute_type'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require 'scim/kit/v2/authentication_scheme'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'scim/kit/v2/complex_attribute_validator'
         
     | 
| 
       7 
8 
     | 
    
         
             
            require 'scim/kit/v2/configuration'
         
     | 
| 
       8 
9 
     | 
    
         
             
            require 'scim/kit/v2/messages'
         
     | 
| 
       9 
10 
     | 
    
         
             
            require 'scim/kit/v2/meta'
         
     | 
| 
         @@ -17,6 +18,7 @@ require 'scim/kit/v2/schemas' 
     | 
|
| 
       17 
18 
     | 
    
         
             
            require 'scim/kit/v2/service_provider_configuration'
         
     | 
| 
       18 
19 
     | 
    
         
             
            require 'scim/kit/v2/supportable'
         
     | 
| 
       19 
20 
     | 
    
         
             
            require 'scim/kit/v2/uniqueness'
         
     | 
| 
      
 21 
     | 
    
         
            +
            require 'scim/kit/v2/unknown_attribute'
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
       21 
23 
     | 
    
         
             
            module Scim
         
     | 
| 
       22 
24 
     | 
    
         
             
              module Kit
         
     | 
| 
         @@ -5,6 +5,8 @@ module Scim 
     | 
|
| 
       5 
5 
     | 
    
         
             
                module V2
         
     | 
| 
       6 
6 
     | 
    
         
             
                  # Represents a dynamic attribute that corresponds to a SCIM type
         
     | 
| 
       7 
7 
     | 
    
         
             
                  module Attributable
         
     | 
| 
      
 8 
     | 
    
         
            +
                    include Enumerable
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       8 
10 
     | 
    
         
             
                    def dynamic_attributes
         
     | 
| 
       9 
11 
     | 
    
         
             
                      @dynamic_attributes ||= {}.with_indifferent_access
         
     | 
| 
       10 
12 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -25,10 +27,8 @@ module Scim 
     | 
|
| 
       25 
27 
     | 
    
         
             
                      end
         
     | 
| 
       26 
28 
     | 
    
         
             
                    end
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                    private
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
30 
     | 
    
         
             
                    def attribute_for(name)
         
     | 
| 
       31 
     | 
    
         
            -
                      dynamic_attributes[name.to_s.underscore]
         
     | 
| 
      
 31 
     | 
    
         
            +
                      dynamic_attributes[name.to_s.underscore] || UnknownAttribute.new(name)
         
     | 
| 
       32 
32 
     | 
    
         
             
                    end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                    def read_attribute(name)
         
     | 
| 
         @@ -42,13 +42,18 @@ module Scim 
     | 
|
| 
       42 
42 
     | 
    
         
             
                      if value.is_a?(Hash)
         
     | 
| 
       43 
43 
     | 
    
         
             
                        attribute_for(name)&.assign_attributes(value)
         
     | 
| 
       44 
44 
     | 
    
         
             
                      else
         
     | 
| 
       45 
     | 
    
         
            -
                         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                        attribute_for(name)._value = value
         
     | 
| 
      
 46 
     | 
    
         
            +
                      end
         
     | 
| 
      
 47 
     | 
    
         
            +
                    end
         
     | 
| 
       47 
48 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
                    def each
         
     | 
| 
      
 50 
     | 
    
         
            +
                      dynamic_attributes.each do |_name, attribute|
         
     | 
| 
      
 51 
     | 
    
         
            +
                        yield attribute
         
     | 
| 
       49 
52 
     | 
    
         
             
                      end
         
     | 
| 
       50 
53 
     | 
    
         
             
                    end
         
     | 
| 
       51 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
                    private
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
       52 
57 
     | 
    
         
             
                    def create_module_for(type)
         
     | 
| 
       53 
58 
     | 
    
         
             
                      name = type.name.to_sym
         
     | 
| 
       54 
59 
     | 
    
         
             
                      Module.new do
         
     | 
| 
         @@ -14,16 +14,21 @@ module Scim 
     | 
|
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
                    validate :presence_of_value, if: proc { |x| x._type.required }
         
     | 
| 
       16 
16 
     | 
    
         
             
                    validate :inclusion_of_value, if: proc { |x| x._type.canonical_values }
         
     | 
| 
       17 
     | 
    
         
            -
                    validate :validate_type
         
     | 
| 
      
 17 
     | 
    
         
            +
                    validate :validate_type, unless: proc { |x| x.complex? }
         
     | 
| 
      
 18 
     | 
    
         
            +
                    validate :validate_complex, if: proc { |x| x.complex? }
         
     | 
| 
      
 19 
     | 
    
         
            +
                    validate :multiple, if: proc { |x| x.multi_valued && !x.complex? }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    delegate :complex?, :multi_valued, to: :_type
         
     | 
| 
       18 
22 
     | 
    
         | 
| 
       19 
23 
     | 
    
         
             
                    def initialize(resource:, type:, value: nil)
         
     | 
| 
       20 
24 
     | 
    
         
             
                      @_type = type
         
     | 
| 
       21 
25 
     | 
    
         
             
                      @_value = value || type.multi_valued ? [] : nil
         
     | 
| 
       22 
26 
     | 
    
         
             
                      @_resource = resource
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       23 
28 
     | 
    
         
             
                      define_attributes_for(resource, type.attributes)
         
     | 
| 
       24 
29 
     | 
    
         
             
                    end
         
     | 
| 
       25 
30 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
                    def _assign(new_value, coerce:  
     | 
| 
      
 31 
     | 
    
         
            +
                    def _assign(new_value, coerce: false)
         
     | 
| 
       27 
32 
     | 
    
         
             
                      @_value = coerce ? _type.coerce(new_value) : new_value
         
     | 
| 
       28 
33 
     | 
    
         
             
                    end
         
     | 
| 
       29 
34 
     | 
    
         | 
| 
         @@ -39,6 +44,10 @@ module Scim 
     | 
|
| 
       39 
44 
     | 
    
         
             
                      true
         
     | 
| 
       40 
45 
     | 
    
         
             
                    end
         
     | 
| 
       41 
46 
     | 
    
         | 
| 
      
 47 
     | 
    
         
            +
                    def each_value(&block)
         
     | 
| 
      
 48 
     | 
    
         
            +
                      Array(_value).each(&block)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       42 
51 
     | 
    
         
             
                    private
         
     | 
| 
       43 
52 
     | 
    
         | 
| 
       44 
53 
     | 
    
         
             
                    def server_only?
         
     | 
| 
         @@ -66,11 +75,28 @@ module Scim 
     | 
|
| 
       66 
75 
     | 
    
         
             
                    end
         
     | 
| 
       67 
76 
     | 
    
         | 
| 
       68 
77 
     | 
    
         
             
                    def validate_type
         
     | 
| 
      
 78 
     | 
    
         
            +
                      return if _value.nil?
         
     | 
| 
       69 
79 
     | 
    
         
             
                      return if _type.valid?(_value)
         
     | 
| 
       70 
80 
     | 
    
         | 
| 
       71 
81 
     | 
    
         
             
                      errors.add(_type.name, I18n.t('errors.messages.invalid'))
         
     | 
| 
       72 
82 
     | 
    
         
             
                    end
         
     | 
| 
       73 
83 
     | 
    
         | 
| 
      
 84 
     | 
    
         
            +
                    def validate_complex
         
     | 
| 
      
 85 
     | 
    
         
            +
                      validates_with ComplexAttributeValidator
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    def multiple
         
     | 
| 
      
 89 
     | 
    
         
            +
                      return unless _value.respond_to?(:to_a)
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                      duped_type = _type.dup
         
     | 
| 
      
 92 
     | 
    
         
            +
                      duped_type.multi_valued = false
         
     | 
| 
      
 93 
     | 
    
         
            +
                      _value.to_a.each do |x|
         
     | 
| 
      
 94 
     | 
    
         
            +
                        unless duped_type.valid?(x)
         
     | 
| 
      
 95 
     | 
    
         
            +
                          errors.add(duped_type.name, I18n.t('errors.messages.invalid'))
         
     | 
| 
      
 96 
     | 
    
         
            +
                        end
         
     | 
| 
      
 97 
     | 
    
         
            +
                      end
         
     | 
| 
      
 98 
     | 
    
         
            +
                    end
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
       74 
100 
     | 
    
         
             
                    def read_only?
         
     | 
| 
       75 
101 
     | 
    
         
             
                      _type.mutability == Mutability::READ_ONLY
         
     | 
| 
       76 
102 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -69,11 +69,9 @@ module Scim 
     | 
|
| 
       69 
69 
     | 
    
         
             
                      if multi_valued
         
     | 
| 
       70 
70 
     | 
    
         
             
                        return value unless value.respond_to?(:to_a)
         
     | 
| 
       71 
71 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                        value.to_a.map  
     | 
| 
       73 
     | 
    
         
            -
                          COERCION.fetch(type, ->(y) { y }).call(x)
         
     | 
| 
       74 
     | 
    
         
            -
                        end
         
     | 
| 
      
 72 
     | 
    
         
            +
                        value.to_a.map { |x| coerce_single(x) }
         
     | 
| 
       75 
73 
     | 
    
         
             
                      else
         
     | 
| 
       76 
     | 
    
         
            -
                         
     | 
| 
      
 74 
     | 
    
         
            +
                        coerce_single(value)
         
     | 
| 
       77 
75 
     | 
    
         
             
                      end
         
     | 
| 
       78 
76 
     | 
    
         
             
                    end
         
     | 
| 
       79 
77 
     | 
    
         | 
| 
         @@ -89,6 +87,13 @@ module Scim 
     | 
|
| 
       89 
87 
     | 
    
         | 
| 
       90 
88 
     | 
    
         
             
                    private
         
     | 
| 
       91 
89 
     | 
    
         | 
| 
      
 90 
     | 
    
         
            +
                    def coerce_single(value)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      COERCION.fetch(type, ->(x) { x }).call(value)
         
     | 
| 
      
 92 
     | 
    
         
            +
                    rescue StandardError => error
         
     | 
| 
      
 93 
     | 
    
         
            +
                      Scim::Kit.logger.error(error)
         
     | 
| 
      
 94 
     | 
    
         
            +
                      value
         
     | 
| 
      
 95 
     | 
    
         
            +
                    end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
       92 
97 
     | 
    
         
             
                    def validate(value)
         
     | 
| 
       93 
98 
     | 
    
         
             
                      complex? ? valid_complex?(value) : valid_simple?(value)
         
     | 
| 
       94 
99 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -0,0 +1,44 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Scim
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Kit
         
     | 
| 
      
 5 
     | 
    
         
            +
                module V2
         
     | 
| 
      
 6 
     | 
    
         
            +
                  # Validates a complex attribute
         
     | 
| 
      
 7 
     | 
    
         
            +
                  class ComplexAttributeValidator < ::ActiveModel::Validator
         
     | 
| 
      
 8 
     | 
    
         
            +
                    def validate(item)
         
     | 
| 
      
 9 
     | 
    
         
            +
                      if item._type.multi_valued
         
     | 
| 
      
 10 
     | 
    
         
            +
                        multi_valued_validation(item)
         
     | 
| 
      
 11 
     | 
    
         
            +
                      else
         
     | 
| 
      
 12 
     | 
    
         
            +
                        item.each do |attribute|
         
     | 
| 
      
 13 
     | 
    
         
            +
                          item.errors.merge!(attribute.errors) unless attribute.valid?
         
     | 
| 
      
 14 
     | 
    
         
            +
                        end
         
     | 
| 
      
 15 
     | 
    
         
            +
                      end
         
     | 
| 
      
 16 
     | 
    
         
            +
                    end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                    private
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                    def multi_valued_validation(item)
         
     | 
| 
      
 21 
     | 
    
         
            +
                      item.each_value do |hash|
         
     | 
| 
      
 22 
     | 
    
         
            +
                        validated = hash.map do |key, value|
         
     | 
| 
      
 23 
     | 
    
         
            +
                          attribute = item.attribute_for(key)
         
     | 
| 
      
 24 
     | 
    
         
            +
                          attribute._assign(value)
         
     | 
| 
      
 25 
     | 
    
         
            +
                          item.errors.merge!(attribute.errors) unless attribute.valid?
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                          key.to_sym
         
     | 
| 
      
 28 
     | 
    
         
            +
                        end
         
     | 
| 
      
 29 
     | 
    
         
            +
                        validate_missing(item, hash, validated)
         
     | 
| 
      
 30 
     | 
    
         
            +
                      end
         
     | 
| 
      
 31 
     | 
    
         
            +
                    end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                    def validate_missing(item, hash, validated)
         
     | 
| 
      
 34 
     | 
    
         
            +
                      not_validated = item.map { |x| x._type.name.to_sym } - validated
         
     | 
| 
      
 35 
     | 
    
         
            +
                      not_validated.each do |key|
         
     | 
| 
      
 36 
     | 
    
         
            +
                        attribute = item.attribute_for(key)
         
     | 
| 
      
 37 
     | 
    
         
            +
                        attribute._assign(hash[key])
         
     | 
| 
      
 38 
     | 
    
         
            +
                        item.errors.merge!(attribute.errors) unless attribute.valid?
         
     | 
| 
      
 39 
     | 
    
         
            +
                      end
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/scim/kit/v2/resource.rb
    CHANGED
    
    
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Scim
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Kit
         
     | 
| 
      
 5 
     | 
    
         
            +
                module V2
         
     | 
| 
      
 6 
     | 
    
         
            +
                  # Represents an Unknown/Unrecognized Attribute
         
     | 
| 
      
 7 
     | 
    
         
            +
                  class UnknownAttribute
         
     | 
| 
      
 8 
     | 
    
         
            +
                    include ::ActiveModel::Validations
         
     | 
| 
      
 9 
     | 
    
         
            +
                    validate :unknown
         
     | 
| 
      
 10 
     | 
    
         
            +
                    attr_reader :name
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    def initialize(name)
         
     | 
| 
      
 13 
     | 
    
         
            +
                      @name = name
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    def _assign(*_args)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      valid?
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                    def _value=(*_args)
         
     | 
| 
      
 21 
     | 
    
         
            +
                      raise Scim::Kit::UnknownAttributeError, name
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    def unknown
         
     | 
| 
      
 25 
     | 
    
         
            +
                      errors.add(name, I18n.t('errors.messages.invalid'))
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/scim/kit/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: scim-kit
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.16
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - mo
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-02-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activemodel
         
     | 
| 
         @@ -177,6 +177,7 @@ files: 
     | 
|
| 
       177 
177 
     | 
    
         
             
            - ".rspec"
         
     | 
| 
       178 
178 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
       179 
179 
     | 
    
         
             
            - ".travis.yml"
         
     | 
| 
      
 180 
     | 
    
         
            +
            - CHANGELOG.md
         
     | 
| 
       180 
181 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       181 
182 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
       182 
183 
     | 
    
         
             
            - README.md
         
     | 
| 
         @@ -197,6 +198,7 @@ files: 
     | 
|
| 
       197 
198 
     | 
    
         
             
            - lib/scim/kit/v2/attribute.rb
         
     | 
| 
       198 
199 
     | 
    
         
             
            - lib/scim/kit/v2/attribute_type.rb
         
     | 
| 
       199 
200 
     | 
    
         
             
            - lib/scim/kit/v2/authentication_scheme.rb
         
     | 
| 
      
 201 
     | 
    
         
            +
            - lib/scim/kit/v2/complex_attribute_validator.rb
         
     | 
| 
       200 
202 
     | 
    
         
             
            - lib/scim/kit/v2/configuration.rb
         
     | 
| 
       201 
203 
     | 
    
         
             
            - lib/scim/kit/v2/error.rb
         
     | 
| 
       202 
204 
     | 
    
         
             
            - lib/scim/kit/v2/messages.rb
         
     | 
| 
         @@ -220,6 +222,7 @@ files: 
     | 
|
| 
       220 
222 
     | 
    
         
             
            - lib/scim/kit/v2/templates/service_provider_configuration.json.jbuilder
         
     | 
| 
       221 
223 
     | 
    
         
             
            - lib/scim/kit/v2/templates/supportable.json.jbuilder
         
     | 
| 
       222 
224 
     | 
    
         
             
            - lib/scim/kit/v2/uniqueness.rb
         
     | 
| 
      
 225 
     | 
    
         
            +
            - lib/scim/kit/v2/unknown_attribute.rb
         
     | 
| 
       223 
226 
     | 
    
         
             
            - lib/scim/kit/version.rb
         
     | 
| 
       224 
227 
     | 
    
         
             
            - scim-kit.gemspec
         
     | 
| 
       225 
228 
     | 
    
         
             
            homepage: https://www.github.com/mokhan/scim-kit
         
     |