Commit 0fb71c8

mokha <mokha@cisco.com>
2019-01-11 19:10:05
move constants to shrink class size
1 parent 0bc6f6b
Changed files (2)
lib/scim/kit/v2/attribute_type.rb
@@ -6,40 +6,6 @@ module Scim
       # Represents a scim Attribute type
       class AttributeType
         include Templatable
-        B64 = %r(\A([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z).freeze
-        BOOLEAN_VALUES = [true, false].freeze
-        DATATYPES = {
-          string: 'string',
-          boolean: 'boolean',
-          decimal: 'decimal',
-          integer: 'integer',
-          datetime: 'dateTime',
-          binary: 'binary',
-          reference: 'reference',
-          complex: 'complex'
-        }.freeze
-        COERCION = {
-          string: ->(x) { x.to_s },
-          decimal: ->(x) { x.to_f },
-          integer: ->(x) { x.to_i },
-          datetime: ->(x) { x.is_a?(::String) ? DateTime.parse(x) : x },
-          binary: ->(x) { Base64.strict_encode64(x) }
-        }.freeze
-        VALIDATIONS = {
-          binary: ->(x) { x.is_a?(String) && x.match?(B64) },
-          boolean: ->(x) { BOOLEAN_VALUES.include?(x) },
-          datetime: ->(x) { x.is_a?(DateTime) },
-          decimal: ->(x) { x.is_a?(Float) },
-          integer: lambda { |x|
-            begin
-              x&.integer?
-            rescue StandardError
-              false
-            end
-          },
-          reference: ->(x) { x =~ /\A#{URI.regexp(%w[http https])}\z/ },
-          string: ->(x) { x.is_a?(String) }
-        }.freeze
         attr_accessor :canonical_values
         attr_accessor :case_exact
         attr_accessor :description
lib/scim/kit/v2.rb
@@ -21,6 +21,43 @@ module Scim
   module Kit
     # Version 2 of the SCIM RFC https://tools.ietf.org/html/rfc7644
     module V2
+      BASE64 = %r(
+        \A([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z
+      )x.freeze
+      BOOLEAN_VALUES = [true, false].freeze
+      DATATYPES = {
+        string: 'string',
+        boolean: 'boolean',
+        decimal: 'decimal',
+        integer: 'integer',
+        datetime: 'dateTime',
+        binary: 'binary',
+        reference: 'reference',
+        complex: 'complex'
+      }.freeze
+      COERCION = {
+        string: ->(x) { x.to_s },
+        decimal: ->(x) { x.to_f },
+        integer: ->(x) { x.to_i },
+        datetime: ->(x) { x.is_a?(::String) ? DateTime.parse(x) : x },
+        binary: ->(x) { Base64.strict_encode64(x) }
+      }.freeze
+      VALIDATIONS = {
+        binary: ->(x) { x.is_a?(String) && x.match?(BASE64) },
+        boolean: ->(x) { BOOLEAN_VALUES.include?(x) },
+        datetime: ->(x) { x.is_a?(DateTime) },
+        decimal: ->(x) { x.is_a?(Float) },
+        integer: lambda { |x|
+          begin
+            x&.integer?
+          rescue StandardError
+            false
+          end
+        },
+        reference: ->(x) { x =~ /\A#{URI.regexp(%w[http https])}\z/ },
+        string: ->(x) { x.is_a?(String) }
+      }.freeze
+
       class << self
         def configuration
           @configuration ||= ::Scim::Kit::V2::Configuration.new