arkaan 2.8.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/arkaan.rb +18 -16
  3. data/lib/arkaan/account.rb +22 -19
  4. data/lib/arkaan/authentication.rb +3 -1
  5. data/lib/arkaan/authentication/session.rb +10 -7
  6. data/lib/arkaan/campaign.rb +21 -19
  7. data/lib/arkaan/campaigns.rb +4 -2
  8. data/lib/arkaan/campaigns/invitation.rb +2 -2
  9. data/lib/arkaan/chatrooms.rb +7 -5
  10. data/lib/arkaan/chatrooms/base.rb +3 -1
  11. data/lib/arkaan/chatrooms/campaign.rb +3 -1
  12. data/lib/arkaan/chatrooms/conversation.rb +5 -1
  13. data/lib/arkaan/chatrooms/membership.rb +6 -2
  14. data/lib/arkaan/chatrooms/message.rb +5 -3
  15. data/lib/arkaan/concerns.rb +10 -8
  16. data/lib/arkaan/concerns/activable.rb +6 -4
  17. data/lib/arkaan/concerns/diagnosticable.rb +7 -5
  18. data/lib/arkaan/concerns/enumerable.rb +21 -9
  19. data/lib/arkaan/concerns/historizable.rb +7 -5
  20. data/lib/arkaan/concerns/mime_typable.rb +18 -10
  21. data/lib/arkaan/concerns/premiumable.rb +3 -1
  22. data/lib/arkaan/concerns/sluggable.rb +9 -8
  23. data/lib/arkaan/concerns/typable.rb +5 -3
  24. data/lib/arkaan/factories.rb +4 -2
  25. data/lib/arkaan/files.rb +6 -2
  26. data/lib/arkaan/files/document.rb +5 -3
  27. data/lib/arkaan/files/permission.rb +4 -2
  28. data/lib/arkaan/monitoring.rb +4 -2
  29. data/lib/arkaan/monitoring/route.rb +6 -3
  30. data/lib/arkaan/monitoring/service.rb +5 -3
  31. data/lib/arkaan/notification.rb +5 -2
  32. data/lib/arkaan/oauth.rb +6 -4
  33. data/lib/arkaan/oauth/access_token.rb +10 -8
  34. data/lib/arkaan/oauth/application.rb +17 -11
  35. data/lib/arkaan/oauth/authorization.rb +8 -6
  36. data/lib/arkaan/oauth/refresh_token.rb +7 -4
  37. data/lib/arkaan/permissions.rb +5 -3
  38. data/lib/arkaan/permissions/category.rb +4 -2
  39. data/lib/arkaan/permissions/group.rb +4 -2
  40. data/lib/arkaan/permissions/right.rb +8 -4
  41. data/lib/arkaan/ruleset.rb +6 -4
  42. metadata +2 -8
  43. data/lib/arkaan/decorators/errors.rb +0 -9
  44. data/lib/arkaan/decorators/errors/env_variable_missing.rb +0 -14
  45. data/lib/arkaan/decorators/gateway.rb +0 -109
  46. data/lib/arkaan/factories/errors.rb +0 -9
  47. data/lib/arkaan/factories/errors/gateway_not_found.rb +0 -14
  48. data/lib/arkaan/version.rb +0 -3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Includes the diagnostic URL field, and the related validations.
@@ -9,14 +11,14 @@ module Arkaan
9
11
  # @author Vincent Courtois <courtois.vincent@outlook.com>
10
12
  included do
11
13
  # @!attribute [rw] diagnostic
12
- # @return [String] the diagnostic URL to know the status of an entity (usually a gateway, or an instance of a service).
14
+ # @return [String] the diagnostic URL to know the status of an instance or a service.
13
15
  field :diagnostic, type: String, default: '/status'
14
16
 
15
17
  validates :diagnostic,
16
- presence: {message: "required"},
17
- length: {minimum: 4, message: "minlength"},
18
- format: {with: /\A(\/[a-z]+)+\z/, message: "pattern"}
18
+ presence: { message: 'required' },
19
+ length: { minimum: 4, message: 'minlength' },
20
+ format: { with: %r{\A(\/[a-z]+)+\z}, message: 'pattern' }
19
21
  end
20
22
  end
21
23
  end
22
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Defines enumerations for the Mongoid models. An enumeration is a field that can only use a given set of values.
@@ -8,7 +10,6 @@ module Arkaan
8
10
  # Submodule holding all the static methods add to the current subclass.
9
11
  # @author Vincent Courtois <courtois.vincent@outlook.com>
10
12
  module ClassMethods
11
-
12
13
  # Creates the field with the given name, set of possible values, and options.
13
14
  # @param field_name [String] the name of the enumerated field.
14
15
  # @param values [Array<Symbol>] the possible values of the enumerated field.
@@ -16,18 +17,33 @@ module Arkaan
16
17
  def enum_field(field_name, values, options = {})
17
18
  returned = field :"enum_#{field_name}", type: Symbol, default: options[:default]
18
19
 
19
- validates :"enum_#{field_name}", inclusion: {in: values.map(&:to_sym), message: 'inclusion'}
20
+ validates :"enum_#{field_name}", inclusion: { in: values.map(&:to_sym), message: 'inclusion' }
21
+
22
+ define_getter(field_name)
23
+
24
+ define_setter(field_name, values)
25
+
26
+ define_values_methods(field_name, values)
27
+
28
+ # This is to make enumerations historizable by
29
+ # returning the field object created by Mongoid.
30
+ returned
31
+ end
20
32
 
33
+ def define_getter(field_name)
21
34
  define_method field_name do
22
35
  return self["enum_#{field_name}"]
23
36
  end
37
+ end
24
38
 
39
+ def define_setter(field_name, values)
25
40
  define_method "#{field_name}=" do |value|
26
- if values.include? value.to_sym
27
- self["enum_#{field_name}"] = value.to_sym
28
- end
41
+ value = value.to_sym
42
+ self["enum_#{field_name}"] = value if values.include? value
29
43
  end
44
+ end
30
45
 
46
+ def define_values_methods(field_name, values)
31
47
  values.map(&:to_sym).each do |value|
32
48
  define_method "#{field_name}_#{value}!" do
33
49
  self["enum_#{field_name}"] = value
@@ -37,10 +53,6 @@ module Arkaan
37
53
  self["enum_#{field_name}"] == value
38
54
  end
39
55
  end
40
-
41
- # This is to make enumerations historizable by
42
- # returning the field object created by Mongoid.
43
- returned
44
56
  end
45
57
  end
46
58
  end
@@ -35,20 +35,22 @@ module Arkaan
35
35
  # Submodule holding all the static methods add to the current subclass.
36
36
  # @author Vincent Courtois <courtois.vincent@outlook.com>
37
37
  module ClassMethods
38
-
39
38
  # Takes the Mongoid declared field and creates the callbacks
40
39
  # to intercept any value change and add it to the history.
41
40
  # @field field [Mongoid::Fields::Standard] the Mongoid field to historize.
42
41
  def historize(field)
42
+ embeds_many :history, class_name: 'Arkaan::Event' unless relations.key?('history')
43
+ historization_after_init(field)
44
+ historization_after_save(field)
45
+ end
43
46
 
44
- unless relations.key?('history')
45
- embeds_many :history, class_name: 'Arkaan::Event'
46
- end
47
-
47
+ def historization_after_init(field)
48
48
  after_initialize do |doc|
49
49
  add_history(field: field.name, from: nil, to: doc[field.name])
50
50
  end
51
+ end
51
52
 
53
+ def historization_after_save(field)
52
54
  after_save do |doc|
53
55
  if doc.changed_attributes.key?(field.name)
54
56
  from = doc.changed_attributes[field.name]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Includes the MIME type field to files to ensure only supported types are included.
@@ -11,32 +13,38 @@ module Arkaan
11
13
  # Defines the MIME type attribute with the given possible MIME types.
12
14
  # @param values [Array<String>] the possible MIME types, * can be used as wild cards.
13
15
  def mime_type(values)
14
-
15
16
  # @!attribute [rw] mime_type
16
17
  # @return [String] the MIME type of the file, obtained from the uploaded file.
17
18
  field :mime_type, type: String
18
-
19
- validates :mime_type, presence: {message: 'required'}
19
+
20
+ validates :mime_type, presence: { message: 'required' }
20
21
 
21
22
  validate :mime_type_validity, if: :mime_type?
22
23
 
24
+ mime_type_check(values)
25
+ end
26
+
27
+ def mime_type_check(values)
23
28
  # Validates the validity of the MIME type by checking if it respects any of the given mime types.
24
29
  # If it does not respect any MIME types possible, it adds an error to the mime_type field and invalidates.
25
30
  define_method :mime_type_validity do
26
- checked_types = if values.is_a? Symbol
27
- self.send(values) rescue []
28
- else
29
- values
30
- end
31
+ checked_types = parse_values(values)
31
32
  return true if checked_types.empty?
33
+
32
34
  checked_types.each do |type|
33
35
  type_regex = ::Regexp.new("^#{type.sub(/\*/, '(.+)')}$")
34
- return true if !type_regex.match(mime_type).nil?
36
+ return true unless type_regex.match(mime_type).nil?
35
37
  end
36
38
  errors.add(:mime_type, 'pattern')
37
39
  end
38
40
  end
41
+
42
+ def parse_values(values)
43
+ values.is_a?(Symbol) ? send(values) : values
44
+ rescue StandardError
45
+ []
46
+ end
39
47
  end
40
48
  end
41
49
  end
42
- end
50
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Includes the premium field to make the entity including it accessible only to premium applications or not.
@@ -12,4 +14,4 @@ module Arkaan
12
14
  end
13
15
  end
14
16
  end
15
- end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Includes the slug field, always the same in all models.
@@ -9,19 +11,18 @@ module Arkaan
9
11
  # @author Vincent Courtois <courtois.vincent@outlook.com>
10
12
  module ClassMethods
11
13
  # Add the field and its validations in the model including it.
12
- # @param entity_type [String,Symbol] the name of the model including it, to be included in the error messages.
13
- def make_sluggable(entity_type)
14
+ def make_sluggable
14
15
  # @!attribute [rw] slug
15
- # @return [String] the slug of the current entity ; it must be snake-cased, longer than four characters, unique for the entity and given.
16
+ # @return [String] the slug of the current entity, in snake-case.
16
17
  field :slug, type: String
17
18
 
18
19
  validates :slug,
19
- length: {minimum: 4, message: 'minlength', if: :slug?},
20
- format: {with: /\A[a-z]+(_[a-z]+)*\z/, message: 'pattern', if: :slug?},
21
- uniqueness: {message: 'uniq', if: :slug?},
22
- presence: {message: 'required'}
20
+ length: { minimum: 4, message: 'minlength', if: :slug? },
21
+ format: { with: /\A[a-z]+(_[a-z]+)*\z/, message: 'pattern', if: :slug? },
22
+ uniqueness: { message: 'uniq', if: :slug? },
23
+ presence: { message: 'required' }
23
24
  end
24
25
  end
25
26
  end
26
27
  end
27
- end
28
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Concerns
3
5
  # Concerns for the objects that can be activated or deactivated, included the corresponding scopes.
@@ -7,11 +9,11 @@ module Arkaan
7
9
 
8
10
  included do
9
11
  include Arkaan::Concerns::Enumerable
10
-
12
+
11
13
  # @!attribute [rw] type
12
14
  # @return [Symbol] the type of the instance, determining its way of being deployed, restarted, etc.
13
- enum_field :type, [:heroku, :local, :unix], default: :heroku
15
+ enum_field :type, %i[heroku local unix], default: :heroku
14
16
  end
15
17
  end
16
18
  end
17
- end
19
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  # Static factories are used to create decorated objects easily.
3
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
6
  module Factories
5
7
  autoload :Gateways, 'arkaan/factories/gateways'
6
- autoload :Errors , 'arkaan/factories/errors'
8
+ autoload :Errors, 'arkaan/factories/errors'
7
9
  end
8
- end
10
+ end
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
4
+ # This module holds all logic for the files uploaded in a conversation.
5
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
2
6
  module Files
3
- autoload :Document , 'arkaan/files/document'
7
+ autoload :Document, 'arkaan/files/document'
4
8
  autoload :Permission, 'arkaan/files/permission'
5
9
  end
6
- end
10
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Files
3
5
  # a document is an uploaded file in the S3 clone application.
@@ -30,9 +32,9 @@ module Arkaan
30
32
  # @return [Array<Arkaan::Files::Permission>] the permissions granted to access this file.
31
33
  has_many :permissions, class_name: 'Arkaan::Files::Permission', inverse_of: :file
32
34
 
33
- validates :name, :extension, :folder, :mime_type, presence: {message: 'required'}
35
+ validates :name, :extension, :folder, :mime_type, presence: { message: 'required' }
34
36
 
35
- validates :folder, format: {without: /\/\//, message: 'format'}
37
+ validates :folder, format: { without: %r{\/\/}, message: 'format' }
36
38
 
37
39
  validate :filename_unicity
38
40
 
@@ -47,4 +49,4 @@ module Arkaan
47
49
  end
48
50
  end
49
51
  end
50
- end
52
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Files
3
5
  # The permission granted to a user to access and/or delete a file.
@@ -9,7 +11,7 @@ module Arkaan
9
11
 
10
12
  # @!attribute [rw] type
11
13
  # @return [Symbol] the type of permission granted (is the user able to delete the file ?)
12
- enum_field :type, [:read, :read_write]
14
+ enum_field :type, %i[read read_write]
13
15
 
14
16
  # @!attribute [rw] file
15
17
  # @return [Arkaan::Files::Document] the document the permission is linked to.
@@ -19,4 +21,4 @@ module Arkaan
19
21
  belongs_to :account, class_name: 'Arkaan::Account', inverse_of: :permissions
20
22
  end
21
23
  end
22
- end
24
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  # The monitoring module holds all the logic about the services so they can be activated or deactivated.
3
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
6
  module Monitoring
5
- autoload :Route , 'arkaan/monitoring/route'
7
+ autoload :Route, 'arkaan/monitoring/route'
6
8
  autoload :Service, 'arkaan/monitoring/service'
7
9
  end
8
- end
10
+ end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Monitoring
3
- # A route is an endpoint accessible in a service. Each route has to have an associated endpoint in the deployed instances.
5
+ # A route is an endpoint accessible in a service. Each route has to have
6
+ # an associated endpoint in the deployed instances.
4
7
  # @param Vincent Courtois <courtois.vincent@outlook.com>
5
8
  class Route
6
9
  include Mongoid::Document
@@ -27,10 +30,10 @@ module Arkaan
27
30
  has_and_belongs_to_many :groups, class_name: 'Arkaan::Permissions::Group', inverse_of: :groups
28
31
 
29
32
  validates :path,
30
- format: {with: /\A(\/|((\/:?[a-zA-Z0-9_]+)+))\z/, message: 'pattern', if: :path?}
33
+ format: { with: %r{\A(\/|((\/:?[a-zA-Z0-9_]+)+))\z}, message: 'pattern', if: :path? }
31
34
 
32
35
  validates :verb,
33
- inclusion: {message: 'unknown', in: ['get', 'post', 'put', 'delete', 'patch', 'option']}
36
+ inclusion: { message: 'unknown', in: %w[get post put delete patch option] }
34
37
 
35
38
  # Returns the complete path, enriched with the path of the service.
36
39
  # @return [String] the complete path to access this route from the outside.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module Monitoring
3
5
  # A service is the representation of one of the applications composing the API.
@@ -23,9 +25,9 @@ module Arkaan
23
25
  # @return [Array<Arkaan::Monitoring::Route>] the routes associated to this service, accessible from the gateway.
24
26
  has_many :routes, class_name: 'Arkaan::Monitoring::Route', inverse_of: :service
25
27
 
26
- validates :key, uniqueness: {message: 'uniq'}
28
+ validates :key, uniqueness: { message: 'uniq' }
27
29
 
28
- validates :path, format: {with: /\A(\/:?[a-z]+)+\z/, message: 'pattern'}
30
+ validates :path, format: { with: %r{\A(\/:?[a-z]+)+\z}, message: 'pattern' }
29
31
  end
30
32
  end
31
- end
33
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  # A notification is a little something to warn a user that an action concerning him or her occurred.
3
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
@@ -12,11 +14,12 @@ module Arkaan
12
14
  # @return [Boolean] TRUE if the notification has been read (seen by the user), FALSE otherwise.
13
15
  field :read, type: Boolean, default: false
14
16
  # @!attribute [rw] data
15
- # @return [Hash] the custom data that can be attached to this notification, for example for an invitation it can be the invited username.
17
+ # @return [Hash] the custom data that can be attached to this notification,
18
+ # for example for an invitation it can be the invited username.
16
19
  field :data, type: Hash, default: {}
17
20
 
18
21
  # @!attribute [rw] account
19
22
  # @return [Arkaan::Account] the account concerned by this notification.
20
23
  embedded_in :account, class_name: 'Arkaan::Account', inverse_of: :notifications
21
24
  end
22
- end
25
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  # This module holds the logic for the connection of an application to our API.
3
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
4
6
  module OAuth
5
- autoload :Application , 'arkaan/oauth/application'
7
+ autoload :Application, 'arkaan/oauth/application'
6
8
  autoload :Authorization, 'arkaan/oauth/authorization'
7
- autoload :AccessToken , 'arkaan/oauth/access_token'
8
- autoload :RefreshToken , 'arkaan/oauth/refresh_token'
9
+ autoload :AccessToken, 'arkaan/oauth/access_token'
10
+ autoload :RefreshToken, 'arkaan/oauth/refresh_token'
9
11
  end
10
- end
12
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module OAuth
3
5
  # An access token is the value assigned to the application
@@ -9,18 +11,18 @@ module Arkaan
9
11
 
10
12
  # @!attribute [rw] value
11
13
  # @return [String] the value of the token, returned to the application when built.
12
- field :value, type: String, default: ->{ SecureRandom.hex }
14
+ field :value, type: String, default: -> { SecureRandom.hex }
13
15
  # @!attribute [rw] expiration
14
- # @return [Integer] the time, in seconds, after which the token is declared expired, and thus can't be used anymore.
15
- field :expiration, type: Integer, default: 86400
16
+ # @return [Integer] the time, in seconds, after which the token is declared expired, and thus can't be used.
17
+ field :expiration, type: Integer, default: 86_400
16
18
 
17
19
  # @!attribute [rw] authorization
18
- # @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application for this user.
20
+ # @return [Arkaan::OAuth::Authorization] the authorization code that issued this token to the application.
19
21
  belongs_to :authorization, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :tokens
20
22
 
21
- validates :value,
22
- presence: {message: 'required'},
23
- uniqueness: {message: 'uniq'}
23
+ validates :value,
24
+ presence: { message: 'required' },
25
+ uniqueness: { message: 'uniq' }
24
26
 
25
27
  # Checks if the current date is inferior to the creation date + expiration period
26
28
  # @return [Boolean] TRUE if the token is expired, FALSE otherwise.
@@ -29,4 +31,4 @@ module Arkaan
29
31
  end
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Arkaan
2
4
  module OAuth
3
- # An application is what is referred to in the OAuth2.0 RFC as a client, wanting to access private informations about the user.
5
+ # An application is what is referred to in the OAuth2.0 RFC as a client,
6
+ # wanting to access private informations about the user.
4
7
  # @author Vincent Courtois <courtois.vincent@outlook.com>
5
8
  class Application
6
9
  include Mongoid::Document
@@ -11,9 +14,10 @@ module Arkaan
11
14
  field :name, type: String
12
15
  # @!attribute [rw] key
13
16
  # @return [String] the unique key for the application, identifying it when requesting a token for the API.
14
- field :application_key, type: String, default: ->{ SecureRandom.hex }
17
+ field :application_key, type: String, default: -> { SecureRandom.hex }
15
18
  # @!attribute [rw] premium
16
- # @return [Boolean] a value indicating whether the application should automatically receive a token when an account is created, or not.
19
+ # @return [Boolean] a value indicating whether the application should automatically receive a token
20
+ # when an account is created, or not.
17
21
  field :premium, type: Boolean, default: false
18
22
  # @!attirbute [rw] redirect_uris
19
23
  # @return [Array<String>] the redirection URIs used for this application.
@@ -23,17 +27,18 @@ module Arkaan
23
27
  # @return [Arkaan::Account] the account that has created this application, considered its owner.
24
28
  belongs_to :creator, class_name: 'Arkaan::Account', inverse_of: :applications
25
29
  # @!attribute [rw] authorizations
26
- # @return [Array<Arkaan::OAuth::Authorization>] the authorizations linked to the accounts this application can get the data from.
30
+ # @return [Array<Arkaan::OAuth::Authorization>] the authorizations linked to the accounts
31
+ # this application can get the data from.
27
32
  has_many :authorizations, class_name: 'Arkaan::OAuth::Authorization', inverse_of: :application
28
33
 
29
34
  validates :name,
30
- presence: {message: 'required'},
31
- length: {minimum: 6, message: 'minlength'},
32
- uniqueness: {message: 'uniq'}
35
+ presence: { message: 'required' },
36
+ length: { minimum: 6, message: 'minlength' },
37
+ uniqueness: { message: 'uniq' }
33
38
 
34
39
  validates :application_key,
35
- presence: {message: 'required'},
36
- uniqueness: {message: 'uniq'}
40
+ presence: { message: 'required' },
41
+ uniqueness: { message: 'uniq' }
37
42
 
38
43
  validate :redirect_uris_values
39
44
 
@@ -41,11 +46,12 @@ module Arkaan
41
46
  # - it is a string
42
47
  # - it has a correct URL format.
43
48
  def redirect_uris_values
49
+ regex = %r{\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z}
44
50
  redirect_uris.each do |uri|
45
51
  if !uri.is_a? String
46
52
  errors.add(:redirect_uris, 'type')
47
53
  break
48
- elsif uri.match(/\A(https?:\/\/)((([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*)|(localhost:[0-9]{2,4})\/?)\z/).nil?
54
+ elsif uri.match(regex).nil?
49
55
  errors.add(:redirect_uris, 'format')
50
56
  break
51
57
  end
@@ -53,4 +59,4 @@ module Arkaan
53
59
  end
54
60
  end
55
61
  end
56
- end
62
+ end