ree_lib 1.0.94 → 1.0.95

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +39 -36
  3. data/lib/ree_lib/packages/ree_errors/Package.schema.json +10 -7
  4. data/lib/ree_lib/packages/ree_errors/package/ree_errors/auth_error.rb +8 -8
  5. data/lib/ree_lib/packages/ree_errors/package/ree_errors/build_error.rb +4 -2
  6. data/lib/ree_lib/packages/ree_errors/package/ree_errors/conflict_error.rb +8 -8
  7. data/lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb +89 -6
  8. data/lib/ree_lib/packages/ree_errors/package/ree_errors/invalid_param_error.rb +9 -9
  9. data/lib/ree_lib/packages/ree_errors/package/ree_errors/not_found_error.rb +8 -8
  10. data/lib/ree_lib/packages/ree_errors/package/ree_errors/payment_required_error.rb +8 -8
  11. data/lib/ree_lib/packages/ree_errors/package/ree_errors/permission_error.rb +8 -8
  12. data/lib/ree_lib/packages/ree_errors/package/ree_errors/validation_error.rb +8 -8
  13. data/lib/ree_lib/packages/ree_errors/package/ree_errors.rb +1 -0
  14. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/auth_error.schema.json +24 -1
  15. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/build_error.schema.json +10 -0
  16. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/conflict_error.schema.json +24 -1
  17. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/invalid_param_error.schema.json +24 -1
  18. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/not_found_error.schema.json +24 -1
  19. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/payment_required_error.schema.json +24 -1
  20. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/permission_error.schema.json +24 -1
  21. data/lib/ree_lib/packages/ree_errors/schemas/ree_errors/validation_error.schema.json +24 -1
  22. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/auth_error_spec.rb +22 -8
  23. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/invalid_param_error_spec.rb +3 -1
  24. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/locales/en.yml +6 -1
  25. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/not_found_error_spec.rb +3 -1
  26. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/payment_required_error_spec.rb +3 -1
  27. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/permission_error_spec.rb +3 -1
  28. data/lib/ree_lib/packages/ree_errors/spec/ree_errors/validation_error_spec.rb +3 -1
  29. data/lib/ree_lib/packages/ree_i18n/Package.schema.json +7 -0
  30. data/lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/check_locale_exists.rb +12 -0
  31. data/lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/check_locale_exists.schema.json +33 -0
  32. data/lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/check_locale_exists.rb +16 -0
  33. data/lib/ree_lib/packages/ree_roda/spec/ree_roda/services/build_swagger_from_routes_spec.rb +7 -4
  34. data/lib/ree_lib/packages/ree_roda/spec/ree_roda/services/locales/en.yml +3 -1
  35. data/lib/ree_lib/packages/ree_string/package/ree_string/functions/deconstantize.rb +1 -1
  36. data/lib/ree_lib/version.rb +1 -1
  37. metadata +5 -3
  38. data/lib/ree_lib/packages/ree_errors/package/ree_errors/error_factory.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 999bb2c56def52960bba5ba42d451d51720732b56c6133c6b2f31138fd5d1b1b
4
- data.tar.gz: fcc8978282f0823ad26d8481c6beba74f3ff622306deabb88a93a466c6b9a476
3
+ metadata.gz: 7e8b705443daf4776540951e35b4f80fb232b95292bd0c1c589124e24914fb7d
4
+ data.tar.gz: aefa991e6d624886cca7052a14b8a126222cdf4e29a0438b1b473b6b62020fe6
5
5
  SHA512:
6
- metadata.gz: cd5215c19233b1cedd2e817f7dfde0d2d034148fc548e9116f8f67b98f6678a4d7435b14119a4282840e1f20d9e87d59708e0490282b59074b2cfe38ab979c4a
7
- data.tar.gz: d3df53d29afbcb3306437ea20e2d4fc6f36d203853737fd1d7359bc31276d744f5ad092dd4283f5ca94cf0cd36e16af1999bddacbbf2f8bd7f5776d9fe103c38
6
+ metadata.gz: c8efb3a06244abe7248da8aefa9438fcab0fad88167ead0017f82ea95aba3b25bf816b093480cb91d87c8948da0af91447c0316d25299e6357e213605f8356fc
7
+ data.tar.gz: cf257f985bcf7a0b7389567480fa53790d771e56e0c45d915fcec10000f719f9ac0e28bee42468e25f7ce158ac705956509de93d70acf465f2edb83bdef4b050
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.94)
4
+ ree_lib (1.0.95)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -15,74 +15,77 @@ PATH
15
15
  GEM
16
16
  remote: https://rubygems.org/
17
17
  specs:
18
- addressable (2.8.6)
19
- public_suffix (>= 2.0.2, < 6.0)
20
- bigdecimal (3.1.6)
21
- binding_of_caller (1.0.0)
22
- debug_inspector (>= 0.0.1)
23
- bootsnap (1.17.1)
18
+ addressable (2.8.7)
19
+ public_suffix (>= 2.0.2, < 7.0)
20
+ bigdecimal (3.1.8)
21
+ binding_of_caller (1.0.1)
22
+ debug_inspector (>= 1.2.0)
23
+ bootsnap (1.18.3)
24
24
  msgpack (~> 1.2)
25
25
  commander (5.0.0)
26
26
  highline (~> 3.0.0)
27
- concurrent-ruby (1.2.3)
28
- crack (0.4.5)
27
+ concurrent-ruby (1.3.3)
28
+ crack (1.0.0)
29
+ bigdecimal
29
30
  rexml
30
31
  crass (1.0.6)
31
32
  debug_inspector (1.2.0)
32
- diff-lcs (1.5.0)
33
- faker (3.2.3)
33
+ diff-lcs (1.5.1)
34
+ faker (3.4.2)
34
35
  i18n (>= 1.8.11, < 2)
35
36
  hashdiff (1.1.0)
36
37
  highline (3.0.1)
37
- i18n (1.14.1)
38
+ i18n (1.14.5)
38
39
  concurrent-ruby (~> 1.0)
39
40
  loofah (2.22.0)
40
41
  crass (~> 1.0.2)
41
42
  nokogiri (>= 1.12.0)
42
43
  msgpack (1.7.2)
43
- nokogiri (1.16.0-x86_64-darwin)
44
+ nokogiri (1.16.7-x86_64-darwin)
44
45
  racc (~> 1.4)
45
- nokogiri (1.16.0-x86_64-linux)
46
+ nokogiri (1.16.7-x86_64-linux)
46
47
  racc (~> 1.4)
47
- oj (3.16.3)
48
+ oj (3.16.4)
48
49
  bigdecimal (>= 3.0)
49
- pg (1.5.4)
50
- public_suffix (5.0.4)
51
- racc (1.7.3)
52
- rack (3.0.8)
50
+ pg (1.5.7)
51
+ public_suffix (6.0.1)
52
+ racc (1.8.0)
53
+ rack (3.1.7)
53
54
  rack-test (2.1.0)
54
55
  rack (>= 1.3)
55
56
  rainbow (3.1.1)
56
- rake (13.1.0)
57
- ree (1.0.35)
57
+ rake (13.2.1)
58
+ ree (1.0.37)
58
59
  commander (~> 5.0.0)
59
- rexml (3.2.6)
60
+ rexml (3.3.2)
61
+ strscan
60
62
  roda (3.76.0)
61
63
  rack
62
- rollbar (3.5.1)
63
- rspec (3.12.0)
64
- rspec-core (~> 3.12.0)
65
- rspec-expectations (~> 3.12.0)
66
- rspec-mocks (~> 3.12.0)
67
- rspec-core (3.12.2)
68
- rspec-support (~> 3.12.0)
69
- rspec-expectations (3.12.3)
64
+ rollbar (3.5.2)
65
+ rspec (3.13.0)
66
+ rspec-core (~> 3.13.0)
67
+ rspec-expectations (~> 3.13.0)
68
+ rspec-mocks (~> 3.13.0)
69
+ rspec-core (3.13.0)
70
+ rspec-support (~> 3.13.0)
71
+ rspec-expectations (3.13.1)
70
72
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.12.0)
72
- rspec-mocks (3.12.6)
73
+ rspec-support (~> 3.13.0)
74
+ rspec-mocks (3.13.1)
73
75
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.12.0)
75
- rspec-support (3.12.1)
76
+ rspec-support (~> 3.13.0)
77
+ rspec-support (3.13.1)
76
78
  ruby-prof (1.7.0)
77
79
  sequel (5.76.0)
78
80
  bigdecimal
79
81
  sqlite3 (1.4.4)
80
- timecop (0.9.8)
82
+ strscan (3.1.0)
83
+ timecop (0.9.10)
81
84
  tzinfo (2.0.6)
82
85
  concurrent-ruby (~> 1.0)
83
86
  warden (1.2.9)
84
87
  rack (>= 2.0.9)
85
- webmock (3.19.1)
88
+ webmock (3.23.1)
86
89
  addressable (>= 2.8.0)
87
90
  crack (>= 0.3.2)
88
91
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -9,6 +9,9 @@
9
9
  "depends_on": [
10
10
  {
11
11
  "name": "ree_i18n"
12
+ },
13
+ {
14
+ "name": "ree_string"
12
15
  }
13
16
  ],
14
17
  "env_vars": [
@@ -19,7 +22,7 @@
19
22
  "name": "auth_error",
20
23
  "schema": "packages/ree_errors/schemas/ree_errors/auth_error.schema.json",
21
24
  "tags": [
22
- "object"
25
+ "fn"
23
26
  ]
24
27
  },
25
28
  {
@@ -33,42 +36,42 @@
33
36
  "name": "conflict_error",
34
37
  "schema": "packages/ree_errors/schemas/ree_errors/conflict_error.schema.json",
35
38
  "tags": [
36
- "object"
39
+ "fn"
37
40
  ]
38
41
  },
39
42
  {
40
43
  "name": "invalid_param_error",
41
44
  "schema": "packages/ree_errors/schemas/ree_errors/invalid_param_error.schema.json",
42
45
  "tags": [
43
- "object"
46
+ "fn"
44
47
  ]
45
48
  },
46
49
  {
47
50
  "name": "not_found_error",
48
51
  "schema": "packages/ree_errors/schemas/ree_errors/not_found_error.schema.json",
49
52
  "tags": [
50
- "object"
53
+ "fn"
51
54
  ]
52
55
  },
53
56
  {
54
57
  "name": "payment_required_error",
55
58
  "schema": "packages/ree_errors/schemas/ree_errors/payment_required_error.schema.json",
56
59
  "tags": [
57
- "object"
60
+ "fn"
58
61
  ]
59
62
  },
60
63
  {
61
64
  "name": "permission_error",
62
65
  "schema": "packages/ree_errors/schemas/ree_errors/permission_error.schema.json",
63
66
  "tags": [
64
- "object"
67
+ "fn"
65
68
  ]
66
69
  },
67
70
  {
68
71
  "name": "validation_error",
69
72
  "schema": "packages/ree_errors/schemas/ree_errors/validation_error.schema.json",
70
73
  "tags": [
71
- "object"
74
+ "fn"
72
75
  ]
73
76
  }
74
77
  ]
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::AuthError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::AuthError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :auth_error do
4
+ fn :auth_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:auth, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :auth, code,locale, msg)
14
14
  end
15
15
  end
@@ -5,14 +5,16 @@ class ReeErrors::BuildError
5
5
  link 'ree_errors/error', -> { Error }
6
6
  end
7
7
 
8
- contract Symbol, Symbol, Nilor[String] => SubclassOf[Error]
9
- def call(type, code, locale)
8
+ contract Any, Symbol, Symbol, Nilor[String], Nilor[String] => SubclassOf[Error]
9
+ def call(caller, type, code, locale, default_msg)
10
10
  klass = Class.new(Error)
11
11
 
12
12
  klass.instance_exec do
13
+ @caller = caller
13
14
  @type = type
14
15
  @code = code
15
16
  @locale = locale
17
+ @default_msg = default_msg
16
18
  end
17
19
 
18
20
  klass
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::ConflictError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::ConflictError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :conflict_error do
4
+ fn :conflict_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:conflict, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :conflict, code,locale, msg)
14
14
  end
15
15
  end
@@ -3,15 +3,46 @@ module ReeErrors
3
3
  include Ree::LinkDSL
4
4
 
5
5
  link :t, from: :ree_i18n
6
+ link :check_locale_exists, from: :ree_i18n
7
+ link :underscore, from: :ree_string
6
8
 
7
9
  def initialize(msg = nil)
8
- if !locale && !msg
9
- raise ArgumentError, "message or locale should be specified"
10
+ if !msg && !locale && !default_msg
11
+ raise ArgumentError, "message, locale or default message should be specified"
10
12
  end
11
13
 
12
- super(
13
- locale ? t(locale, default_by_locale: :en) : msg
14
- )
14
+ message = if msg
15
+ msg
16
+ elsif default_msg
17
+ default_msg
18
+ else
19
+ path = (locale || code).to_s
20
+ has_path = path.include?(".")
21
+
22
+ if has_path
23
+ pre_path = [caller_module, caller_class].compact.map { underscore(_)}.join(".")
24
+
25
+ if check_locale_exists(path)
26
+ t(path, default_by_locale: :en)
27
+ else
28
+ t("#{pre_path}.#{path}", default_by_locale: :en)
29
+ end
30
+ else
31
+ if caller_module
32
+ mod = underscore(caller_module)
33
+ klass = underscore(caller_class)
34
+
35
+ if check_locale_exists(loc = "#{mod}.errors.#{klass}.#{path}")
36
+ t(loc, default_by_locale: :en)
37
+ else check_locale_exists(loc = "#{mod}.errors.#{path}")
38
+ t(loc, default_by_locale: :en)
39
+ end
40
+ else
41
+ end
42
+ end
43
+ end
44
+
45
+ super(message)
15
46
  end
16
47
 
17
48
  def type
@@ -26,20 +57,72 @@ module ReeErrors
26
57
  t
27
58
  end
28
59
 
60
+ def default_msg
61
+ self.class.instance_variable_get(:@default_msg)
62
+ end
63
+
29
64
  def locale
30
65
  self.class.instance_variable_get(:@locale)
31
66
  end
32
67
 
68
+ def caller
69
+ self.class.instance_variable_get(:@caller)
70
+ end
71
+
72
+ def caller_module
73
+ @caller_module ||= begin
74
+ if !caller
75
+ nil
76
+ else
77
+ c = caller
78
+
79
+ if c.is_a?(Class)
80
+ extract_module_name(c.to_s)
81
+ else
82
+ extract_module_name(c.class.to_s)
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def caller_class
89
+ @caller_class ||= begin
90
+ if !caller
91
+ nil
92
+ else
93
+ c = caller
94
+
95
+ if c.is_a?(Class)
96
+ extract_class_name(c.to_s)
97
+ else
98
+ extract_class_name(c.class.to_s)
99
+ end
100
+ end
101
+ end
102
+ end
103
+
33
104
  def code
34
105
  c = self.class.instance_variable_get(:@code)
35
106
 
36
107
  if !c
37
108
  raise ArgumentError.new(
38
- "code was not specified for domain error => #{self.inspect}"
109
+ "code not specified for error => #{self.inspect}"
39
110
  )
40
111
  end
41
112
 
42
113
  c
43
114
  end
115
+
116
+ private
117
+
118
+ def extract_module_name(klass_str)
119
+ class_name = klass_str.split("::").first
120
+ return nil if class_name == klass_str
121
+ return class_name
122
+ end
123
+
124
+ def extract_class_name(klass_str)
125
+ klass_str.split("::").last
126
+ end
44
127
  end
45
128
  end
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::InvalidParamError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::InvalidParamError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :invalid_param_error do
4
+ fn :invalid_param_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:invalid_param, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :invalid_param, code,locale, msg)
14
14
  end
15
- end
15
+ end
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::NotFoundError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::NotFoundError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :not_found_error do
4
+ fn :not_found_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:not_found, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :not_found, code,locale, msg)
14
14
  end
15
15
  end
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::PaymentRequiredError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::PaymentRequiredError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :payment_required_error do
4
+ fn :payment_required_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:payment_required, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :payment_required, code,locale, msg)
14
14
  end
15
15
  end
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::PermissionError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::PermissionError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :permission_error do
4
+ fn :permission_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:permission, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :permission, code,locale, msg)
14
14
  end
15
15
  end
@@ -1,15 +1,15 @@
1
- require_relative 'error_factory'
1
+ class ReeErrors::ValidationError
2
+ include Ree::FnDSL
2
3
 
3
- class ReeErrors::ValidationError < ReeErrors::ErrorFactory
4
- include Ree::BeanDSL
5
-
6
- bean :validation_error do
4
+ fn :validation_error do
5
+ target :class
6
+ with_caller
7
7
  link :build_error
8
8
  link 'ree_errors/error', -> { Error }
9
9
  end
10
10
 
11
- contract Symbol, Nilor[String] => SubclassOf[Error]
12
- def build(code, locale = nil)
13
- build_error(:validation, code, locale)
11
+ contract Symbol, Nilor[String], Kwargs[msg: Nilor[String]] => SubclassOf[Error]
12
+ def call(code, locale = nil, msg: nil)
13
+ build_error(get_caller, :validation, code,locale, msg)
14
14
  end
15
15
  end
@@ -3,5 +3,6 @@ module ReeErrors
3
3
 
4
4
  package do
5
5
  depends_on :ree_i18n
6
+ depends_on :ree_string
6
7
  end
7
8
  end
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "auth_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/auth_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::AuthError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -14,6 +14,11 @@
14
14
  ],
15
15
  "return": "SubclassOf[ReeErrors::Error]",
16
16
  "args": [
17
+ {
18
+ "arg": "caller",
19
+ "arg_type": "req",
20
+ "type": "Any"
21
+ },
17
22
  {
18
23
  "arg": "type",
19
24
  "arg_type": "req",
@@ -28,6 +33,11 @@
28
33
  "arg": "locale",
29
34
  "arg_type": "req",
30
35
  "type": "Nilor[String]"
36
+ },
37
+ {
38
+ "arg": "default_msg",
39
+ "arg_type": "req",
40
+ "type": "Nilor[String]"
31
41
  }
32
42
  ]
33
43
  }
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "conflict_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/conflict_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::ConflictError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "invalid_param_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/invalid_param_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::InvalidParamError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "not_found_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/not_found_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::NotFoundError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "payment_required_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/payment_required_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::PaymentRequiredError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "permission_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/permission_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::PermissionError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -3,11 +3,34 @@
3
3
  "schema_version": "1.1",
4
4
  "name": "validation_error",
5
5
  "path": "packages/ree_errors/package/ree_errors/validation_error.rb",
6
- "mount_as": "object",
6
+ "mount_as": "fn",
7
7
  "class": "ReeErrors::ValidationError",
8
8
  "factory": null,
9
9
  "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
10
13
 
14
+ ],
15
+ "return": "SubclassOf[ReeErrors::Error]",
16
+ "args": [
17
+ {
18
+ "arg": "code",
19
+ "arg_type": "req",
20
+ "type": "Symbol"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[String]"
26
+ },
27
+ {
28
+ "arg": "msg",
29
+ "arg_type": "key",
30
+ "type": "Nilor[String]"
31
+ }
32
+ ]
33
+ }
11
34
  ],
12
35
  "links": [
13
36
  {
@@ -2,25 +2,27 @@ package_require('ree_errors/auth_error')
2
2
 
3
3
  RSpec.describe ReeErrors::AuthError do
4
4
  link :add_load_path, from: :ree_i18n
5
+ link :auth_error, from: :ree_errors
5
6
 
6
7
  before :all do
7
8
  add_load_path(Dir[File.join(__dir__, 'locales/*.yml')])
8
9
  end
9
10
 
10
11
  it {
11
- klass = described_class.build(:code, 'ree_errors_test.error')
12
- error = klass.new('CUSTOM MESSAGE')
12
+ klass = auth_error(:code, 'ree_errors_test.error', msg: "test")
13
+ error = klass.new
13
14
 
14
15
  expect(klass).to be_a(Class)
15
16
  expect(error).to be_a(ReeErrors::Error)
16
- expect(error.message).to eq('test error message')
17
+ expect(error.message).to eq('test')
17
18
  expect(error.code).to eq(:code)
18
19
  expect(error.type).to eq(:auth)
19
20
  expect(error.locale).to eq('ree_errors_test.error')
21
+ expect(error.caller).to eq(self)
20
22
  }
21
23
 
22
24
  it {
23
- klass = described_class.build(:code)
25
+ klass = auth_error(:code)
24
26
 
25
27
  expect {
26
28
  klass.new
@@ -28,7 +30,7 @@ RSpec.describe ReeErrors::AuthError do
28
30
  }
29
31
 
30
32
  it {
31
- klass = described_class.build(:code)
33
+ klass = auth_error(:code)
32
34
  error = klass.new('CUSTOM MESSAGE')
33
35
 
34
36
  expect(klass).to be_a(Class)
@@ -40,14 +42,26 @@ RSpec.describe ReeErrors::AuthError do
40
42
  }
41
43
 
42
44
  it {
43
- klass = described_class.build(:code, 'ree_errors_test.error')
45
+ klass = auth_error(:code, 'locale_error')
46
+ error = klass.new
47
+
48
+ expect(klass).to be_a(Class)
49
+ expect(error).to be_a(ReeErrors::Error)
50
+ expect(error.message).to eq('locale error')
51
+ expect(error.code).to eq(:code)
52
+ expect(error.type).to eq(:auth)
53
+ expect(error.locale).to eq("locale_error")
54
+ }
55
+
56
+ it {
57
+ klass = auth_error(:code, 'locale_error1')
44
58
  error = klass.new
45
59
 
46
60
  expect(klass).to be_a(Class)
47
61
  expect(error).to be_a(ReeErrors::Error)
48
- expect(error.message).to eq('test error message')
62
+ expect(error.message).to eq('locale error 1')
49
63
  expect(error.code).to eq(:code)
50
64
  expect(error.type).to eq(:auth)
51
- expect(error.locale).to eq("ree_errors_test.error")
65
+ expect(error.locale).to eq("locale_error1")
52
66
  }
53
67
  end
@@ -1,8 +1,10 @@
1
1
  package_require('ree_errors/invalid_param_error')
2
2
 
3
3
  RSpec.describe ReeErrors::InvalidParamError do
4
+ link :invalid_param_error, from: :ree_errors
5
+
4
6
  it {
5
- klass = described_class.build(:code)
7
+ klass = invalid_param_error(:code)
6
8
  error = klass.new('message')
7
9
 
8
10
  expect(klass).to be_a(Class)
@@ -1,3 +1,8 @@
1
1
  en:
2
2
  ree_errors_test:
3
- error: 'test error message'
3
+ error: 'test error message'
4
+ r_spec:
5
+ errors:
6
+ locale_error1: "locale error 1"
7
+ ree_errors_auth_error:
8
+ locale_error: "locale error"
@@ -1,8 +1,10 @@
1
1
  package_require('ree_errors/not_found_error')
2
2
 
3
3
  RSpec.describe ReeErrors::NotFoundError do
4
+ link :not_found_error, from: :ree_errors
5
+
4
6
  it {
5
- klass = described_class.build(:code)
7
+ klass = not_found_error(:code)
6
8
  error = klass.new('message')
7
9
 
8
10
  expect(klass).to be_a(Class)
@@ -1,8 +1,10 @@
1
1
  package_require('ree_errors/payment_required_error')
2
2
 
3
3
  RSpec.describe ReeErrors::PaymentRequiredError do
4
+ link :payment_required_error, from: :ree_errors
5
+
4
6
  it {
5
- klass = described_class.build(:code)
7
+ klass = payment_required_error(:code)
6
8
  error = klass.new('message')
7
9
 
8
10
  expect(klass).to be_a(Class)
@@ -1,8 +1,10 @@
1
1
  package_require('ree_errors/permission_error')
2
2
 
3
3
  RSpec.describe ReeErrors::PermissionError do
4
+ link :permission_error, from: :ree_errors
5
+
4
6
  it {
5
- klass = described_class.build(:code)
7
+ klass = permission_error(:code)
6
8
  error = klass.new('message')
7
9
 
8
10
  expect(klass).to be_a(Class)
@@ -1,8 +1,10 @@
1
1
  package_require('ree_errors/validation_error')
2
2
 
3
3
  RSpec.describe ReeErrors::ValidationError do
4
+ link :validation_error, from: :ree_errors
5
+
4
6
  it {
5
- klass = described_class.build(:code)
7
+ klass = validation_error(:code)
6
8
  error = klass.new('message')
7
9
 
8
10
  expect(klass).to be_a(Class)
@@ -25,6 +25,13 @@
25
25
  "fn"
26
26
  ]
27
27
  },
28
+ {
29
+ "name": "check_locale_exists",
30
+ "schema": "packages/ree_i18n/schemas/ree_i18n/functions/check_locale_exists.schema.json",
31
+ "tags": [
32
+ "fn"
33
+ ]
34
+ },
28
35
  {
29
36
  "name": "get_default_locale",
30
37
  "schema": "packages/ree_i18n/schemas/ree_i18n/functions/get_default_locale.schema.json",
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ReeI18n::CheckLocaleExists
4
+ include Ree::FnDSL
5
+
6
+ fn :check_locale_exists
7
+
8
+ contract(String, Nilor[Or[String, Symbol]] => Bool)
9
+ def call(value, locale = nil)
10
+ I18n.exists?(value, locale || I18n.default_locale)
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ {
2
+ "schema_type": "object",
3
+ "schema_version": "1.1",
4
+ "name": "check_locale_exists",
5
+ "path": "packages/ree_i18n/package/ree_i18n/functions/check_locale_exists.rb",
6
+ "mount_as": "fn",
7
+ "class": "ReeI18n::CheckLocaleExists",
8
+ "factory": null,
9
+ "methods": [
10
+ {
11
+ "doc": "",
12
+ "throws": [
13
+
14
+ ],
15
+ "return": "Bool",
16
+ "args": [
17
+ {
18
+ "arg": "value",
19
+ "arg_type": "req",
20
+ "type": "String"
21
+ },
22
+ {
23
+ "arg": "locale",
24
+ "arg_type": "opt",
25
+ "type": "Nilor[Or[String, Symbol]]"
26
+ }
27
+ ]
28
+ }
29
+ ],
30
+ "links": [
31
+
32
+ ]
33
+ }
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe :check_locale_exists do
4
+ link :set_locale, from: :ree_i18n
5
+ link :get_locale, from: :ree_i18n
6
+ link :add_load_path, from: :ree_i18n
7
+
8
+ it {
9
+ add_load_path(Dir[File.join(__dir__, 'locales/*.yml')])
10
+
11
+ expect(check_locale_exists("count.zero", "ru")).to eq(true)
12
+ expect(check_locale_exists("count.zero")).to eq(true)
13
+ expect(check_locale_exists("count.zero", :fr)).to eq(false)
14
+ expect(check_locale_exists("count.none", :ru)).to eq(false)
15
+ }
16
+ end
@@ -17,19 +17,22 @@ RSpec.describe :build_swagger_from_routes do
17
17
  package do
18
18
  depends_on :ree_actions
19
19
  depends_on :ree_dao
20
+ depends_on :ree_errors
20
21
  end
21
22
  end
22
23
 
23
24
  class ReeRodaTestSwagger::Cmd
24
25
  include ReeActions::DSL
25
26
 
26
- action :cmd
27
+ action :cmd do
28
+ link :invalid_param_error, from: :ree_errors
29
+ end
27
30
 
28
31
  ActionCaster = build_mapper.use(:cast) do
29
32
  integer :id
30
33
  end
31
34
 
32
- InvalidErr = ReeErrors::ValidationError.build(:invalid, "invalid")
35
+ InvalidErr = invalid_param_error(:invalid, "invalid")
33
36
 
34
37
  contract(Any, Any => Any).throws(InvalidErr)
35
38
  def call(access, attrs)
@@ -71,7 +74,7 @@ RSpec.describe :build_swagger_from_routes do
71
74
  it {
72
75
  swagger = build_swagger_from_routes(routes, "test", "test", "1.0", "https://example.com")
73
76
 
74
- expect(swagger.dig(:paths, "/api/actions", :post, :responses, 422, :description))
75
- .to eq("- type: **validation**, code: **invalid**, message: **invalid**")
77
+ expect(swagger.dig(:paths, "/api/actions", :post, :responses, 400, :description))
78
+ .to eq("- type: **invalid_param**, code: **invalid**, message: **invalid param**")
76
79
  }
77
80
  end
@@ -1,2 +1,4 @@
1
1
  en:
2
- invalid: "invalid"
2
+ ree_roda_test_swagger:
3
+ errors:
4
+ invalid: "invalid param"
@@ -7,7 +7,7 @@ class ReeString::Deconstantize
7
7
 
8
8
  doc(<<~DOC)
9
9
  Removes the rightmost segment from the constant expression in the string.
10
-
10
+
11
11
  deconstantize('Net::HTTP') # => "Net"
12
12
  deconstantize('::Net::HTTP') # => "::Net"
13
13
  deconstantize('String') # => ""
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.94"
4
+ VERSION = "1.0.95"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.94
4
+ version: 1.0.95
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ree
@@ -836,7 +836,6 @@ files:
836
836
  - lib/ree_lib/packages/ree_errors/package/ree_errors/build_error.rb
837
837
  - lib/ree_lib/packages/ree_errors/package/ree_errors/conflict_error.rb
838
838
  - lib/ree_lib/packages/ree_errors/package/ree_errors/error.rb
839
- - lib/ree_lib/packages/ree_errors/package/ree_errors/error_factory.rb
840
839
  - lib/ree_lib/packages/ree_errors/package/ree_errors/invalid_param_error.rb
841
840
  - lib/ree_lib/packages/ree_errors/package/ree_errors/not_found_error.rb
842
841
  - lib/ree_lib/packages/ree_errors/package/ree_errors/payment_required_error.rb
@@ -933,6 +932,7 @@ files:
933
932
  - lib/ree_lib/packages/ree_i18n/bin/console
934
933
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n.rb
935
934
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/add_load_path.rb
935
+ - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/check_locale_exists.rb
936
936
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/get_default_locale.rb
937
937
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/get_locale.rb
938
938
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/set_default_locale.rb
@@ -940,6 +940,7 @@ files:
940
940
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/t.rb
941
941
  - lib/ree_lib/packages/ree_i18n/package/ree_i18n/functions/with_locale.rb
942
942
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/add_load_path.schema.json
943
+ - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/check_locale_exists.schema.json
943
944
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/get_default_locale.schema.json
944
945
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/get_locale.schema.json
945
946
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/set_default_locale.schema.json
@@ -947,6 +948,7 @@ files:
947
948
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/t.schema.json
948
949
  - lib/ree_lib/packages/ree_i18n/schemas/ree_i18n/functions/with_locale.schema.json
949
950
  - lib/ree_lib/packages/ree_i18n/spec/package_schema_spec.rb
951
+ - lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/check_locale_exists.rb
950
952
  - lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/locales/en.yml
951
953
  - lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/locales/ru.yml
952
954
  - lib/ree_lib/packages/ree_i18n/spec/ree_i18n/functions/set_locale_spec.rb
@@ -1,15 +0,0 @@
1
- require_relative 'error'
2
-
3
- class ReeErrors::ErrorFactory
4
- class << self
5
- contract Symbol, String => SubclassOf[ReeErrors::Error]
6
- def build(code, locale = nil)
7
- self.new.build(code, locale)
8
- end
9
- end
10
-
11
- contract Symbol, String => SubclassOf[ReeErrors::Error]
12
- def build(code, locale = nil)
13
- raise NotImplementedError, "should be implemented in derived class"
14
- end
15
- end