commons_yellowme 0.11.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +62 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +218 -0
  6. data/bin/test +5 -0
  7. data/commons.gemspec +36 -0
  8. data/lib/commons.rb +1 -1
  9. data/lib/commons/concerns/extensions/soft_deleted.rb +34 -0
  10. data/lib/commons/formatter/regex_constants.rb +2 -0
  11. data/lib/commons/repositories/base_repository.rb +59 -54
  12. data/lib/commons/services/concerns/callable.rb +7 -2
  13. data/lib/commons/version.rb +1 -1
  14. data/spec/commons/authentication/authenticate_by_jwt_spec.rb +37 -0
  15. data/spec/commons/authentication/json_web_token_spec.rb +41 -0
  16. data/spec/commons/concerns/attributes/sex_spec.rb +24 -0
  17. data/spec/commons/concerns/extensions/deleted_spec.rb +40 -0
  18. data/spec/commons/concerns/guard/capitalizable_spec.rb +13 -0
  19. data/spec/commons/concerns/validations/undestroyable_spec.rb +9 -0
  20. data/spec/commons/errors/bad_request_spec.rb +62 -0
  21. data/spec/commons/errors/conflict_spec.rb +62 -0
  22. data/spec/commons/errors/forbidden_spec.rb +62 -0
  23. data/spec/commons/errors/internal_server_error_spec.rb +62 -0
  24. data/spec/commons/errors/invalid_resource_spec.rb +62 -0
  25. data/spec/commons/errors/maintenance_mode_spec.rb +49 -0
  26. data/spec/commons/errors/missing_parameter_spec.rb +49 -0
  27. data/spec/commons/errors/not_unique_spec.rb +62 -0
  28. data/spec/commons/errors/payment_required_spec.rb +62 -0
  29. data/spec/commons/errors/precondition_failed_spec.rb +62 -0
  30. data/spec/commons/errors/resource_not_found_spec.rb +49 -0
  31. data/spec/commons/errors/route_not_found_spec.rb +49 -0
  32. data/spec/commons/errors/unauthorized_spec.rb +62 -0
  33. data/spec/commons/errors/unprocessable_entity_spec.rb +62 -0
  34. data/spec/commons/formatter/e164_phone_spec.rb +155 -0
  35. data/spec/commons/formatter/regex_constants_spec.rb +165 -0
  36. data/spec/commons/formatter/string_utils_spec.rb +19 -0
  37. data/spec/commons/repositories/base_repository_spec.rb +516 -0
  38. data/spec/commons/repositories/catalogs/base_catalog_spec.rb +55 -0
  39. data/spec/commons/serializers/bad_request_spec.rb +46 -0
  40. data/spec/commons/serializers/conflict_spec.rb +46 -0
  41. data/spec/commons/serializers/forbidden_spec.rb +46 -0
  42. data/spec/commons/serializers/internal_server_error_spec.rb +46 -0
  43. data/spec/commons/serializers/invalid_resource_spec.rb +46 -0
  44. data/spec/commons/serializers/maintenance_mode_spec.rb +46 -0
  45. data/spec/commons/serializers/missing_parameter_spec.rb +44 -0
  46. data/spec/commons/serializers/not_unique_spec.rb +46 -0
  47. data/spec/commons/serializers/payment_required_spec.rb +46 -0
  48. data/spec/commons/serializers/precondition_failed_spec.rb +46 -0
  49. data/spec/commons/serializers/route_not_found_spec.rb +46 -0
  50. data/spec/commons/serializers/unauthorized_spec.rb +46 -0
  51. data/spec/commons/serializers/unprocessable_entity_spec.rb +46 -0
  52. data/spec/commons/shared-examples/user_spec.rb +18 -0
  53. data/spec/dummy/.ruby-version +1 -0
  54. data/spec/dummy/Rakefile +6 -0
  55. data/spec/dummy/app/assets/config/manifest.js +2 -0
  56. data/spec/dummy/app/assets/images/.keep +0 -0
  57. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  58. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  59. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  60. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  61. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  62. data/spec/dummy/app/controllers/miscellaneous_controller.rb +13 -0
  63. data/spec/dummy/app/errors/default_handling.rb +35 -0
  64. data/spec/dummy/app/errors/error_notifier.rb +12 -0
  65. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  66. data/spec/dummy/app/javascript/packs/application.js +15 -0
  67. data/spec/dummy/app/jobs/application_job.rb +7 -0
  68. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  69. data/spec/dummy/app/models/application_record.rb +3 -0
  70. data/spec/dummy/app/models/catalogs/application_parameter.rb +6 -0
  71. data/spec/dummy/app/models/concerns/.keep +0 -0
  72. data/spec/dummy/app/models/employee.rb +3 -0
  73. data/spec/dummy/app/models/user.rb +16 -0
  74. data/spec/dummy/app/repositories/catalogs/application_parameter_repository.rb +4 -0
  75. data/spec/dummy/app/repositories/employee_repository.rb +2 -0
  76. data/spec/dummy/app/repositories/user_repository.rb +2 -0
  77. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  78. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  79. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  80. data/spec/dummy/bin/rails +4 -0
  81. data/spec/dummy/bin/rake +4 -0
  82. data/spec/dummy/bin/setup +33 -0
  83. data/spec/dummy/config.ru +5 -0
  84. data/spec/dummy/config/application.rb +29 -0
  85. data/spec/dummy/config/boot.rb +5 -0
  86. data/spec/dummy/config/cable.yml +10 -0
  87. data/spec/dummy/config/database.yml +25 -0
  88. data/spec/dummy/config/environment.rb +5 -0
  89. data/spec/dummy/config/environments/development.rb +62 -0
  90. data/spec/dummy/config/environments/production.rb +112 -0
  91. data/spec/dummy/config/environments/test.rb +48 -0
  92. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  93. data/spec/dummy/config/initializers/assets.rb +12 -0
  94. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  95. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  96. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  97. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  98. data/spec/dummy/config/initializers/inflections.rb +16 -0
  99. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  100. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  101. data/spec/dummy/config/locales/en.yml +33 -0
  102. data/spec/dummy/config/puma.rb +38 -0
  103. data/spec/dummy/config/routes.rb +9 -0
  104. data/spec/dummy/config/spring.rb +6 -0
  105. data/spec/dummy/config/storage.yml +34 -0
  106. data/spec/dummy/db/migrate/20191212233443_create_user.rb +13 -0
  107. data/spec/dummy/db/migrate/20191213072543_create_application_parameters.rb +8 -0
  108. data/spec/dummy/db/migrate/20200101204534_create_employee.rb +8 -0
  109. data/spec/dummy/db/schema.rb +35 -0
  110. data/spec/dummy/lib/assets/.keep +0 -0
  111. data/spec/dummy/log/.keep +0 -0
  112. data/spec/dummy/public/404.html +67 -0
  113. data/spec/dummy/public/422.html +67 -0
  114. data/spec/dummy/public/500.html +66 -0
  115. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  116. data/spec/dummy/public/apple-touch-icon.png +0 -0
  117. data/spec/dummy/public/favicon.ico +0 -0
  118. data/spec/factories/catalogs/application_parameters.rb +6 -0
  119. data/spec/factories/employees.rb +6 -0
  120. data/spec/factories/users.rb +7 -0
  121. data/spec/rails_helper.rb +68 -0
  122. data/spec/spec_helper.rb +108 -0
  123. data/spec/support/shared-examples/capitalizable.rb +16 -0
  124. data/spec/support/shared-examples/deletable.rb +39 -0
  125. data/spec/support/shared-examples/dimorphic.rb +28 -0
  126. data/spec/support/shared-examples/stripable.rb +17 -0
  127. data/spec/support/shared-examples/undestroyable.rb +8 -0
  128. metadata +249 -13
  129. data/lib/commons/concerns/extensions/deleted.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72561778339f9301bc276ec516c4bf13d3e98323c93ba4a7bfce41d67dcca9d2
4
- data.tar.gz: 9036b246544ec395c0cfb7829bdbea2b85deb1cbf14b465c8aacf3eaaf56c709
3
+ metadata.gz: d79985617cba32b33138c8436f656da439a49a01edb041982449e0ac4d59cffc
4
+ data.tar.gz: 97b8f3428026c1e89eedad0c4d80ad626805098ec2bf260d73f47916e1a9cb3c
5
5
  SHA512:
6
- metadata.gz: 563e23f1dfecd7805b3e274327365fe77a789db503cb421e00773d4ada57fb990456cfc5dea53fb0a411d1622074e4ef5985e851f54bce516ae6237d5863c785
7
- data.tar.gz: 87e562f16d6f70f1c870c6db5ade5f5ae3c48601704e7040f7c327f8ad7c3c42b56a345268a68fa2bc1c04965b5ab672512f9d46bd3dc83144eb31afc18c762d
6
+ metadata.gz: 05621d09bb7a699c797f8edb87362a046769ca960855ded4f6323d6d61ae8c1b3e49ab34489e494ac8371387fa4bc02c3e02c7550ca5bea2b9e9f73300da25ad
7
+ data.tar.gz: b008246db762536c3dadd45db51023eb9db7edfe30acf69225db58b15529290a49e727585964fe23f7feb59a163b8bf24c5cbdbef09ac157643d1a6b9fa3278e
@@ -0,0 +1,62 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ .vscode
13
+
14
+ # Used by dotenv library to load environment variables.
15
+ # .env
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+ *.bridgesupport
22
+ build-iPhoneOS/
23
+ build-iPhoneSimulator/
24
+
25
+ ## Specific to RubyMotion (use of CocoaPods):
26
+ #
27
+ # We recommend against adding the Pods directory to your .gitignore. However
28
+ # you should judge for yourself, the pros and cons are mentioned at:
29
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
30
+ #
31
+ # vendor/Pods/
32
+
33
+ ## Documentation cache and generated files:
34
+ /.yardoc/
35
+ /_yardoc/
36
+ /doc/
37
+ /rdoc/
38
+
39
+ ## Environment normalization:
40
+ /.bundle/
41
+ /vendor/bundle
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+ .DS_Store
53
+
54
+ .bundle/
55
+ log/*.log
56
+ pkg/
57
+ spec/dummy/db/*.sqlite3
58
+ spec/dummy/db/*.sqlite3-journal
59
+ spec/dummy/db/*.sqlite3-*
60
+ spec/dummy/log/*.log
61
+ spec/dummy/storage/
62
+ spec/dummy/tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --require rails_helper
3
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in commons.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
@@ -0,0 +1,218 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ commons_yellowme (0.13.0)
5
+ active_model_serializers (~> 0.10.10)
6
+ dry-validation
7
+ json (~> 2.0)
8
+ jwt
9
+ phonelib (~> 0.6.29)
10
+ rails (~> 5.2)
11
+ strip_attributes
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ actioncable (5.2.4.1)
17
+ actionpack (= 5.2.4.1)
18
+ nio4r (~> 2.0)
19
+ websocket-driver (>= 0.6.1)
20
+ actionmailer (5.2.4.1)
21
+ actionpack (= 5.2.4.1)
22
+ actionview (= 5.2.4.1)
23
+ activejob (= 5.2.4.1)
24
+ mail (~> 2.5, >= 2.5.4)
25
+ rails-dom-testing (~> 2.0)
26
+ actionpack (5.2.4.1)
27
+ actionview (= 5.2.4.1)
28
+ activesupport (= 5.2.4.1)
29
+ rack (~> 2.0, >= 2.0.8)
30
+ rack-test (>= 0.6.3)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
33
+ actionview (5.2.4.1)
34
+ activesupport (= 5.2.4.1)
35
+ builder (~> 3.1)
36
+ erubi (~> 1.4)
37
+ rails-dom-testing (~> 2.0)
38
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
39
+ active_model_serializers (0.10.10)
40
+ actionpack (>= 4.1, < 6.1)
41
+ activemodel (>= 4.1, < 6.1)
42
+ case_transform (>= 0.2)
43
+ jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
44
+ activejob (5.2.4.1)
45
+ activesupport (= 5.2.4.1)
46
+ globalid (>= 0.3.6)
47
+ activemodel (5.2.4.1)
48
+ activesupport (= 5.2.4.1)
49
+ activerecord (5.2.4.1)
50
+ activemodel (= 5.2.4.1)
51
+ activesupport (= 5.2.4.1)
52
+ arel (>= 9.0)
53
+ activestorage (5.2.4.1)
54
+ actionpack (= 5.2.4.1)
55
+ activerecord (= 5.2.4.1)
56
+ marcel (~> 0.3.1)
57
+ activesupport (5.2.4.1)
58
+ concurrent-ruby (~> 1.0, >= 1.0.2)
59
+ i18n (>= 0.7, < 2)
60
+ minitest (~> 5.1)
61
+ tzinfo (~> 1.1)
62
+ arel (9.0.0)
63
+ builder (3.2.4)
64
+ case_transform (0.2)
65
+ activesupport
66
+ concurrent-ruby (1.1.5)
67
+ crass (1.0.6)
68
+ diff-lcs (1.3)
69
+ docile (1.3.2)
70
+ dry-configurable (0.9.0)
71
+ concurrent-ruby (~> 1.0)
72
+ dry-core (~> 0.4, >= 0.4.7)
73
+ dry-container (0.7.2)
74
+ concurrent-ruby (~> 1.0)
75
+ dry-configurable (~> 0.1, >= 0.1.3)
76
+ dry-core (0.4.9)
77
+ concurrent-ruby (~> 1.0)
78
+ dry-equalizer (0.3.0)
79
+ dry-inflector (0.2.0)
80
+ dry-initializer (3.0.3)
81
+ dry-logic (1.0.6)
82
+ concurrent-ruby (~> 1.0)
83
+ dry-core (~> 0.2)
84
+ dry-equalizer (~> 0.2)
85
+ dry-schema (1.4.3)
86
+ concurrent-ruby (~> 1.0)
87
+ dry-configurable (~> 0.8, >= 0.8.3)
88
+ dry-core (~> 0.4)
89
+ dry-equalizer (~> 0.2)
90
+ dry-initializer (~> 3.0)
91
+ dry-logic (~> 1.0)
92
+ dry-types (~> 1.2)
93
+ dry-types (1.3.0)
94
+ concurrent-ruby (~> 1.0)
95
+ dry-container (~> 0.3)
96
+ dry-core (~> 0.4, >= 0.4.4)
97
+ dry-equalizer (~> 0.3)
98
+ dry-inflector (~> 0.1, >= 0.1.2)
99
+ dry-logic (~> 1.0, >= 1.0.2)
100
+ dry-validation (1.4.2)
101
+ concurrent-ruby (~> 1.0)
102
+ dry-container (~> 0.7, >= 0.7.1)
103
+ dry-core (~> 0.4)
104
+ dry-equalizer (~> 0.2)
105
+ dry-initializer (~> 3.0)
106
+ dry-schema (~> 1.4, >= 1.4.3)
107
+ erubi (1.9.0)
108
+ factory_bot (5.1.1)
109
+ activesupport (>= 4.2.0)
110
+ factory_bot_rails (5.1.1)
111
+ factory_bot (~> 5.1.0)
112
+ railties (>= 4.2.0)
113
+ faker (2.8.1)
114
+ i18n (>= 1.6, < 1.8)
115
+ globalid (0.4.2)
116
+ activesupport (>= 4.2.0)
117
+ i18n (1.7.1)
118
+ concurrent-ruby (~> 1.0)
119
+ json (2.3.0)
120
+ jsonapi-renderer (0.2.2)
121
+ jwt (2.2.1)
122
+ loofah (2.4.0)
123
+ crass (~> 1.0.2)
124
+ nokogiri (>= 1.5.9)
125
+ mail (2.7.1)
126
+ mini_mime (>= 0.1.1)
127
+ marcel (0.3.3)
128
+ mimemagic (~> 0.3.2)
129
+ method_source (0.9.2)
130
+ mimemagic (0.3.4)
131
+ mini_mime (1.0.2)
132
+ mini_portile2 (2.4.0)
133
+ minitest (5.14.0)
134
+ nio4r (2.5.2)
135
+ nokogiri (1.10.7)
136
+ mini_portile2 (~> 2.4.0)
137
+ phonelib (0.6.41)
138
+ rack (2.1.2)
139
+ rack-test (1.1.0)
140
+ rack (>= 1.0, < 3)
141
+ rails (5.2.4.1)
142
+ actioncable (= 5.2.4.1)
143
+ actionmailer (= 5.2.4.1)
144
+ actionpack (= 5.2.4.1)
145
+ actionview (= 5.2.4.1)
146
+ activejob (= 5.2.4.1)
147
+ activemodel (= 5.2.4.1)
148
+ activerecord (= 5.2.4.1)
149
+ activestorage (= 5.2.4.1)
150
+ activesupport (= 5.2.4.1)
151
+ bundler (>= 1.3.0)
152
+ railties (= 5.2.4.1)
153
+ sprockets-rails (>= 2.0.0)
154
+ rails-dom-testing (2.0.3)
155
+ activesupport (>= 4.2.0)
156
+ nokogiri (>= 1.6)
157
+ rails-html-sanitizer (1.3.0)
158
+ loofah (~> 2.3)
159
+ railties (5.2.4.1)
160
+ actionpack (= 5.2.4.1)
161
+ activesupport (= 5.2.4.1)
162
+ method_source
163
+ rake (>= 0.8.7)
164
+ thor (>= 0.19.0, < 2.0)
165
+ rake (13.0.1)
166
+ rspec-core (3.9.0)
167
+ rspec-support (~> 3.9.0)
168
+ rspec-expectations (3.9.0)
169
+ diff-lcs (>= 1.2.0, < 2.0)
170
+ rspec-support (~> 3.9.0)
171
+ rspec-mocks (3.9.0)
172
+ diff-lcs (>= 1.2.0, < 2.0)
173
+ rspec-support (~> 3.9.0)
174
+ rspec-rails (3.9.0)
175
+ actionpack (>= 3.0)
176
+ activesupport (>= 3.0)
177
+ railties (>= 3.0)
178
+ rspec-core (~> 3.9.0)
179
+ rspec-expectations (~> 3.9.0)
180
+ rspec-mocks (~> 3.9.0)
181
+ rspec-support (~> 3.9.0)
182
+ rspec-support (3.9.0)
183
+ simplecov (0.17.1)
184
+ docile (~> 1.1)
185
+ json (>= 1.8, < 3)
186
+ simplecov-html (~> 0.10.0)
187
+ simplecov-html (0.10.2)
188
+ sprockets (4.0.0)
189
+ concurrent-ruby (~> 1.0)
190
+ rack (> 1, < 3)
191
+ sprockets-rails (3.2.1)
192
+ actionpack (>= 4.0)
193
+ activesupport (>= 4.0)
194
+ sprockets (>= 3.0.0)
195
+ sqlite3 (1.4.1)
196
+ strip_attributes (1.9.0)
197
+ activemodel (>= 3.0, < 7.0)
198
+ thor (1.0.1)
199
+ thread_safe (0.3.6)
200
+ tzinfo (1.2.6)
201
+ thread_safe (~> 0.1)
202
+ websocket-driver (0.7.1)
203
+ websocket-extensions (>= 0.1.0)
204
+ websocket-extensions (0.1.4)
205
+
206
+ PLATFORMS
207
+ ruby
208
+
209
+ DEPENDENCIES
210
+ commons_yellowme!
211
+ factory_bot_rails (~> 5.1.1)
212
+ faker
213
+ rspec-rails
214
+ simplecov
215
+ sqlite3
216
+
217
+ BUNDLED WITH
218
+ 2.1.4
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path("../test", __dir__)
3
+
4
+ require "bundler/setup"
5
+ require "rails/plugin/test"
@@ -0,0 +1,36 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "commons/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "commons_yellowme"
9
+ spec.version = Commons::VERSION
10
+ spec.date = '2019-12-10'
11
+ spec.summary = "Commons is Yellowme's Rails APIs utilities gem"
12
+ spec.description = "Commons is Yellowme's Rails APIs utilities gem"
13
+ spec.authors = ["Yellowme"]
14
+ spec.email = 'hola@yellowme.mx'
15
+ spec.homepage = 'https://github.com/yellowme/commons-rails'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+
22
+
23
+ spec.add_dependency "rails", "~> 6.0"
24
+ spec.add_dependency 'json', '~> 2.0'
25
+ spec.add_dependency "active_model_serializers", "~> 0.10.10"
26
+ spec.add_dependency "strip_attributes"
27
+ spec.add_dependency "jwt"
28
+ spec.add_dependency "dry-validation"
29
+ spec.add_dependency "phonelib", "~> 0.6.29"
30
+
31
+ spec.add_development_dependency "sqlite3"
32
+ spec.add_development_dependency "rspec-rails"
33
+ spec.add_development_dependency "factory_bot_rails", "~> 5.1.1"
34
+ spec.add_development_dependency "faker"
35
+ spec.add_development_dependency "simplecov"
36
+ end
@@ -24,7 +24,7 @@ require 'commons/services/concerns/callable'
24
24
 
25
25
  # models
26
26
  require 'commons/concerns/attributes/sex'
27
- require 'commons/concerns/extensions/deleted'
27
+ require 'commons/concerns/extensions/soft_deleted'
28
28
  require 'commons/concerns/guard/capitalizable'
29
29
  require 'commons/concerns/validations/undestroyable'
30
30
 
@@ -0,0 +1,34 @@
1
+ module Commons
2
+ module Concerns
3
+ module Extensions
4
+ module SoftDeleted
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ before_validation :check_not_deleted, on: [:update]
9
+
10
+ def deleted?
11
+ raise ActiveModel::MissingAttributeError unless has_required_fields?
12
+ self.deleted_at.present?
13
+ end
14
+
15
+ def self.default_scope
16
+ raise ActiveModel::MissingAttributeError unless has_attribute?(:deleted_at)
17
+ where(deleted_at: nil)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def check_not_deleted
24
+ raise ActiveModel::MissingAttributeError unless has_required_fields?
25
+ raise ActiveRecord::RecordInvalid if self.deleted_at_in_database.present?
26
+ end
27
+
28
+ def has_required_fields?
29
+ self.has_attribute?(:deleted_at)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -4,6 +4,8 @@ module Commons
4
4
  PROPER_NOUN = /\A\p{L}[\p{L}'\.\-]*( [\p{L}'\.\-]+)*\z/u
5
5
  CURP = /\A([A-Z][AEIOUX][A-Z]{2}\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])[HM](?:AS|B[CS]|C[CLMSH]|D[FG]|G[TR]|HG|JC|M[CNS]|N[ETL]|OC|PL|Q[TR]|S[PLR]|T[CSL]|VZ|YN|ZS)[B-DF-HJ-NP-TV-Z]{3}[A-Z\d])(\d)\z/
6
6
  RFC = /\A([A-ZÑ\x26]{3,4}(\d{2})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[0-1])([A-Z0-9]){2}([A0-9]))?\z/i
7
+ ELECTOR_KEY = /\A(?:[A-Z][B-DF-HJ-NP-TV-Z]){3}\d{2}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])(?:0[1-9]|[12]\d|3[0-2]|99)[A-Z]\d{3}\z/
8
+ MONEY = /\A[+-]?\d+(\.\d{1,6})?\z/
7
9
  end
8
10
  end
9
11
  end
@@ -4,54 +4,47 @@ module Commons
4
4
  include Singleton
5
5
 
6
6
  #
7
- # Método que devuelve todos los objetos
7
+ # Método que devuelve todos los objetos activos
8
8
  #
9
- # @return [Object,nil]
9
+ # @return [Arrat<Object>, nil]
10
10
  #
11
- def all
12
- @db_client.all
13
- end
11
+ delegate :all, to: :@db_client
14
12
 
15
13
  #
16
14
  # Método que devuelve todos los objetos que no han sido eliminados
17
15
  #
18
16
  # @return [Object,nil]
19
17
  #
20
- def kept
21
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
22
-
23
- @db_client.where(deleted_at: nil)
24
- end
18
+ delegate :where, to: :@db_client
19
+ alias_method :query, :where
25
20
 
26
21
  #
27
22
  # Método que devuelve todos los objetos que han sido eliminados
28
23
  #
29
- # @return [Object,nil]
24
+ # @return [Object, nil]
30
25
  #
31
26
  def deleted
32
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
27
+ raise ActiveModel::MissingAttributeError unless @db_client.include? Commons::Concerns::Extensions::SoftDeleted
33
28
 
34
- @db_client.where.not(deleted_at: nil)
29
+ @db_client.unscoped.where.not(deleted_at: nil)
35
30
  end
36
31
 
37
32
  #
38
33
  # Método que devuelve el objeto según su ID
39
34
  #
40
- # @return [Object,nil]
35
+ # @return [Object, nil]
41
36
  #
42
- def find(id)
43
- @db_client.find(id)
44
- end
37
+ delegate :find, to: :@db_client
45
38
 
46
39
  #
47
40
  # Método que devuelve el objeto según su ID
48
41
  #
49
42
  # @return [Object,nil]
50
43
  #
51
- def find_kept(id)
52
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
44
+ def find_deleted(id)
45
+ raise ActiveModel::MissingAttributeError unless @db_client.include? Commons::Concerns::Extensions::SoftDeleted
53
46
 
54
- @db_client.find_by!(id: id, deleted_at: nil)
47
+ @db_client.unscoped.where(id: id).where.not(deleted_at: nil).first
55
48
  end
56
49
 
57
50
  #
@@ -59,22 +52,17 @@ module Commons
59
52
  #
60
53
  # @return [Object,nil]
61
54
  #
62
- def find_by(params)
63
- @db_client.find_by(params)
64
- end
55
+ delegate :find_by, to: :@db_client
65
56
 
66
57
  #
67
58
  # Método que devuelve el objeto según parámetros
68
59
  #
69
60
  # @return [Object,nil]
70
61
  #
71
- def find_kept_by(params)
72
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
62
+ def find_deleted_by(params)
63
+ raise ActiveModel::MissingAttributeError unless @db_client.include? Commons::Concerns::Extensions::SoftDeleted
73
64
 
74
- @db_client.find_by(
75
- deleted_at: nil,
76
- **params
77
- )
65
+ @db_client.unscoped.where.not(deleted_at: nil).where(**params).first
78
66
  end
79
67
 
80
68
  #
@@ -84,9 +72,7 @@ module Commons
84
72
  #
85
73
  # @raise [ActiveRecord::RecordNotFound]
86
74
  #
87
- def find_by!(params)
88
- @db_client.find_by!(params)
89
- end
75
+ delegate :find_by!, to: :@db_client
90
76
 
91
77
  #
92
78
  # Método que devuelve el objeto según parámetros
@@ -95,13 +81,10 @@ module Commons
95
81
  #
96
82
  # @raise [ActiveRecord::RecordNotFound]
97
83
  #
98
- def find_kept_by!(params)
99
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
84
+ def find_deleted_by!(params)
85
+ raise ActiveModel::MissingAttributeError unless @db_client.include? Commons::Concerns::Extensions::SoftDeleted
100
86
 
101
- @db_client.find_by!(
102
- deleted_at: nil,
103
- **params
104
- )
87
+ @db_client.unscoped.where.not(deleted_at: nil).where(**params).first!
105
88
  end
106
89
 
107
90
  #
@@ -115,9 +98,10 @@ module Commons
115
98
  # @raise [ActiveRecord::RecordNotSaved]
116
99
  #
117
100
  def create!(object)
118
- raise ArgumentError unless object.is_a? @db_client
101
+ raise ArgumentError unless object.is_a?(@db_client)
102
+ raise ActiveRecord::RecordInvalid.new(object) unless object.valid?
119
103
 
120
- object.save!
104
+ save_object(object)
121
105
  end
122
106
 
123
107
  #
@@ -143,10 +127,7 @@ module Commons
143
127
  #
144
128
  # @raises [ActiveRecord::RecordInvalid]
145
129
  #
146
- def find_or_create_by!(params, &block)
147
- object = @db_client.find_by(params) || @db_client.create!(params, &block)
148
- object
149
- end
130
+ delegate :find_or_create_by!, to: :@db_client
150
131
 
151
132
  #
152
133
  # Método que realiza una busqueda de la primer entrada,
@@ -174,7 +155,13 @@ module Commons
174
155
  # @raise [ActiveRecord::RecordNotSaved]
175
156
  #
176
157
  def update!(object)
177
- create!(object)
158
+ if !object.is_a?(@db_client) || object.id.blank?
159
+ raise ArgumentError
160
+ end
161
+
162
+ raise ActiveRecord::RecordInvalid.new(object) unless object.valid?
163
+
164
+ save_object(object)
178
165
  end
179
166
 
180
167
  #
@@ -203,25 +190,43 @@ module Commons
203
190
  # @raises [ActiveRecord::RecordInvalid]
204
191
  # @raises [ActiveModel::MissingAttributeError]
205
192
  #
206
- def soft_delete!(id)
207
- raise ActiveModel::MissingAttributeError unless @db_client.column_names.include? "deleted_at"
208
-
209
- object = @db_client.find_by!(id: id, deleted_at: nil)
210
- object.update!(deleted_at: Time.current)
211
-
212
- object
193
+ def destroy!(object)
194
+ if @db_client.include? Commons::Concerns::Extensions::SoftDeleted
195
+ soft_delete!(object)
196
+ else
197
+ hard_delete!(object)
198
+ end
213
199
  end
214
200
 
215
- private
201
+ protected
216
202
 
217
203
  def initialize
218
- @db_client ||= class_object
204
+ @db_client = class_object
219
205
  end
220
206
 
221
207
  def class_object
222
208
  model_name = self.class.to_s.gsub("Repository", "")
223
209
  Object.const_get model_name
224
210
  end
211
+
212
+ private
213
+
214
+ def save_object(object)
215
+ object.save
216
+ end
217
+
218
+ def soft_delete!(object)
219
+ raise ActiveModel::MissingAttributeError unless @db_client.column_names.include?("deleted_at")
220
+ object.update!(deleted_at: Time.current)
221
+
222
+ object
223
+ end
224
+
225
+ def hard_delete!(object)
226
+ object.destroy!
227
+
228
+ object
229
+ end
225
230
  end
226
231
  end
227
232
  end