resource_quotable 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/Changelog.md +17 -0
  3. data/MIT-LICENSE +20 -0
  4. data/Rakefile +18 -0
  5. data/Readme.md +206 -0
  6. data/app/assets/config/resource_quotable_manifest.js +1 -0
  7. data/app/assets/stylesheets/resource_quotable/application.css +15 -0
  8. data/app/controllers/resource_quotable/application_controller.rb +15 -0
  9. data/app/controllers/resource_quotable/quota_controller.rb +106 -0
  10. data/app/controllers/resource_quotable/quotum_trackers_controller.rb +23 -0
  11. data/app/models/resource_quotable/application_record.rb +7 -0
  12. data/app/models/resource_quotable/quotum.rb +46 -0
  13. data/app/models/resource_quotable/quotum_tracker.rb +60 -0
  14. data/app/services/resource_quotable/action_services/base.rb +23 -0
  15. data/app/services/resource_quotable/action_services/check.rb +19 -0
  16. data/app/services/resource_quotable/action_services/check_multiple.rb +23 -0
  17. data/app/services/resource_quotable/action_services/increment.rb +18 -0
  18. data/app/services/resource_quotable/action_services/increment_multiple.rb +22 -0
  19. data/app/services/resource_quotable/base.rb +24 -0
  20. data/app/services/resource_quotable/create.rb +29 -0
  21. data/app/services/resource_quotable/destroy.rb +14 -0
  22. data/app/services/resource_quotable/quotum_tracker_services/reset.rb +17 -0
  23. data/app/services/resource_quotable/reset/all.rb +16 -0
  24. data/app/services/resource_quotable/reset/any.rb +16 -0
  25. data/app/services/resource_quotable/reset/base.rb +22 -0
  26. data/app/services/resource_quotable/reset/daily.rb +16 -0
  27. data/app/services/resource_quotable/reset/monthly.rb +16 -0
  28. data/app/services/resource_quotable/reset/weekly.rb +16 -0
  29. data/app/services/resource_quotable/reset/yearly.rb +16 -0
  30. data/app/services/resource_quotable/update.rb +23 -0
  31. data/app/views/layouts/resource_quotable/application.html.erb +15 -0
  32. data/app/views/resource_quotable/quota/_edit.html.erb +11 -0
  33. data/app/views/resource_quotable/quota/_index.html.erb +43 -0
  34. data/app/views/resource_quotable/quota/_new.html.erb +34 -0
  35. data/app/views/resource_quotable/quota/_show.html.erb +41 -0
  36. data/app/views/resource_quotable/quota/create.js.erb +3 -0
  37. data/app/views/resource_quotable/quota/destroy.js.erb +3 -0
  38. data/app/views/resource_quotable/quota/edit.html.erb +1 -0
  39. data/app/views/resource_quotable/quota/edit.js.erb +1 -0
  40. data/app/views/resource_quotable/quota/index/_row.html.erb +3 -0
  41. data/app/views/resource_quotable/quota/index/_row_content.html.erb +43 -0
  42. data/app/views/resource_quotable/quota/index.html.erb +1 -0
  43. data/app/views/resource_quotable/quota/index.js.erb +1 -0
  44. data/app/views/resource_quotable/quota/new.html.erb +1 -0
  45. data/app/views/resource_quotable/quota/new.js.erb +1 -0
  46. data/app/views/resource_quotable/quota/show/_row.html.erb +3 -0
  47. data/app/views/resource_quotable/quota/show/_row_content.html.erb +7 -0
  48. data/app/views/resource_quotable/quota/show.html.erb +1 -0
  49. data/app/views/resource_quotable/quota/show.js.erb +1 -0
  50. data/app/views/resource_quotable/quota/update.js.erb +3 -0
  51. data/app/views/resource_quotable/quotum_trackers/index/_row_content.html.erb +8 -0
  52. data/app/views/resource_quotable/quotum_trackers/reset.js.erb +3 -0
  53. data/config/routes.rb +11 -0
  54. data/db/migrate/20220805102601_create_resource_quotable_quota.rb +17 -0
  55. data/db/migrate/20220811072023_create_resource_quotable_quotum_trackers.rb +18 -0
  56. data/lib/concerns/controllers/allowed_to_manage_quota_check.rb +73 -0
  57. data/lib/concerns/models/act_as_quota_trackable.rb +23 -0
  58. data/lib/concerns/models/act_as_quotable.rb +19 -0
  59. data/lib/resource_quotable/engine.rb +13 -0
  60. data/lib/resource_quotable/exeptions.rb +9 -0
  61. data/lib/resource_quotable/generators/views_generator.rb +18 -0
  62. data/lib/resource_quotable/helper.rb +27 -0
  63. data/lib/resource_quotable/version.rb +5 -0
  64. data/lib/resource_quotable.rb +68 -0
  65. data/lib/tasks/resource_quotable_tasks.rake +5 -0
  66. metadata +322 -0
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResourceQuotable
4
+ class Engine < ::Rails::Engine # :nodoc:
5
+ isolate_namespace ResourceQuotable
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec
9
+ g.fixture_replacement :factory_bot
10
+ g.factory_bot dir: 'spec/factories'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResourceQuotable
4
+ class QuotaLimitError < StandardError; end
5
+ class QuotaMultiLimitError < StandardError; end
6
+ class QuotaDuplicateError < StandardError; end
7
+ class AbstractClassError < StandardError; end
8
+ class AuthorizationError < StandardError; end
9
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ module ResourceQuotable
6
+ module Generators
7
+ class ViewsGenerator < Rails::Generators::Base # :nodoc:
8
+ desc 'Create ResourceQuotable views template in your app/views folder.'
9
+
10
+ source_root File.expand_path('../../../app/views', __dir__)
11
+ # check_class_collision suffix: 'resource_quotable'
12
+
13
+ def create_views
14
+ directory 'resource_quotable', 'app/views/resource_quotable'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResourceQuotable
4
+ module Helper # :nodoc:
5
+ def resource_quotable
6
+ content_tag(:div, '', id: ResourceQuotable.main_content)
7
+ end
8
+
9
+ def method_missing(method, *args, &block)
10
+ if can_be_delegated?(method)
11
+ main_app.send(method, *args, &block)
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ def respond_to_missing?(method, *)
18
+ can_be_delegated?(method) || super
19
+ end
20
+
21
+ protected
22
+
23
+ def can_be_delegated?(method)
24
+ (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && main_app.respond_to?(method)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ResourceQuotable
4
+ VERSION = '0.2.0'
5
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'resource_quotable/version'
4
+ require 'resource_quotable/engine'
5
+ require 'resource_quotable/exeptions'
6
+ require 'resource_quotable/helper'
7
+ require 'resource_quotable/generators/views_generator'
8
+ require 'concerns/models/act_as_quotable'
9
+ require 'concerns/models/act_as_quota_trackable'
10
+ require 'concerns/controllers/allowed_to_manage_quota_check'
11
+
12
+ require 'kaminari'
13
+
14
+ module ResourceQuotable # :nodoc:
15
+ mattr_accessor :users_method
16
+ mattr_accessor :group_method
17
+ mattr_accessor :resources
18
+ mattr_accessor :actions
19
+ mattr_accessor :main_content
20
+ mattr_accessor :base_controller
21
+ mattr_accessor :layout
22
+
23
+ DEFAULT_ACTIONS = {
24
+ create: 0,
25
+ update: 1,
26
+ destroy: 2
27
+ }.freeze
28
+
29
+ def self.users_method
30
+ @@users_method.to_s || 'users'
31
+ end
32
+
33
+ def self.group_method
34
+ @@group_method.to_s || 'group'
35
+ end
36
+
37
+ def self.resources
38
+ @@resources
39
+ end
40
+
41
+ def self.actions
42
+ @@actions.empty? ? DEFAULT_ACTIONS : @@actions
43
+ end
44
+
45
+ def self.main_content
46
+ @@main_content.empty? ? 'resource_quotable_content' : @@main_content
47
+ end
48
+
49
+ def self.base_controller
50
+ @@base_controller.constantize
51
+ end
52
+
53
+ def self.layout
54
+ @@layout || 'application'
55
+ end
56
+
57
+ # Default way to set up ResourceQuotable. Run rails generate resource_quotable_install to create
58
+ # a fresh initializer with all configuration values.
59
+ def self.setup
60
+ yield self
61
+ end
62
+ end
63
+
64
+ # Extend ActiveRecord::Base with associations
65
+ ActiveRecord::Base.include ResourceQuotable::ActsAsQuotable
66
+ ActiveRecord::Base.include ResourceQuotable::ActsAsQuotaTrackable
67
+ ActionController::Base.include ResourceQuotable::AllowedToManageQuotaCheck
68
+ ActionView::Base.include ResourceQuotable::Helper
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :resource_quotable do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,322 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resource_quotable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Ngel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kaminari
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.2'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '7'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.2'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '7'
53
+ - !ruby/object:Gem::Dependency
54
+ name: annotate
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.2'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '3.2'
67
+ - !ruby/object:Gem::Dependency
68
+ name: database_cleaner-active_record
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '2.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: factory_bot_rails
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '6.2'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '6.2'
95
+ - !ruby/object:Gem::Dependency
96
+ name: ffaker
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.21'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.21'
109
+ - !ruby/object:Gem::Dependency
110
+ name: generator_spec
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.9'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.9'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rails-controller-testing
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '1.0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rspec-rails
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '5.1'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '5.1'
151
+ - !ruby/object:Gem::Dependency
152
+ name: rubocop
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '1.33'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '1.33'
165
+ - !ruby/object:Gem::Dependency
166
+ name: rubocop-rails
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.15'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '2.15'
179
+ - !ruby/object:Gem::Dependency
180
+ name: rubocop-rspec
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - "~>"
184
+ - !ruby/object:Gem::Version
185
+ version: '2.12'
186
+ type: :development
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: '2.12'
193
+ - !ruby/object:Gem::Dependency
194
+ name: shoulda-matchers
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '5.1'
200
+ type: :development
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '5.1'
207
+ - !ruby/object:Gem::Dependency
208
+ name: simplecov
209
+ requirement: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '0.21'
214
+ type: :development
215
+ prerelease: false
216
+ version_requirements: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - "~>"
219
+ - !ruby/object:Gem::Version
220
+ version: '0.21'
221
+ description: Flexible quota system for resources.
222
+ email:
223
+ - ngel@protonmail.com
224
+ executables: []
225
+ extensions: []
226
+ extra_rdoc_files: []
227
+ files:
228
+ - Changelog.md
229
+ - MIT-LICENSE
230
+ - Rakefile
231
+ - Readme.md
232
+ - app/assets/config/resource_quotable_manifest.js
233
+ - app/assets/stylesheets/resource_quotable/application.css
234
+ - app/controllers/resource_quotable/application_controller.rb
235
+ - app/controllers/resource_quotable/quota_controller.rb
236
+ - app/controllers/resource_quotable/quotum_trackers_controller.rb
237
+ - app/models/resource_quotable/application_record.rb
238
+ - app/models/resource_quotable/quotum.rb
239
+ - app/models/resource_quotable/quotum_tracker.rb
240
+ - app/services/resource_quotable/action_services/base.rb
241
+ - app/services/resource_quotable/action_services/check.rb
242
+ - app/services/resource_quotable/action_services/check_multiple.rb
243
+ - app/services/resource_quotable/action_services/increment.rb
244
+ - app/services/resource_quotable/action_services/increment_multiple.rb
245
+ - app/services/resource_quotable/base.rb
246
+ - app/services/resource_quotable/create.rb
247
+ - app/services/resource_quotable/destroy.rb
248
+ - app/services/resource_quotable/quotum_tracker_services/reset.rb
249
+ - app/services/resource_quotable/reset/all.rb
250
+ - app/services/resource_quotable/reset/any.rb
251
+ - app/services/resource_quotable/reset/base.rb
252
+ - app/services/resource_quotable/reset/daily.rb
253
+ - app/services/resource_quotable/reset/monthly.rb
254
+ - app/services/resource_quotable/reset/weekly.rb
255
+ - app/services/resource_quotable/reset/yearly.rb
256
+ - app/services/resource_quotable/update.rb
257
+ - app/views/layouts/resource_quotable/application.html.erb
258
+ - app/views/resource_quotable/quota/_edit.html.erb
259
+ - app/views/resource_quotable/quota/_index.html.erb
260
+ - app/views/resource_quotable/quota/_new.html.erb
261
+ - app/views/resource_quotable/quota/_show.html.erb
262
+ - app/views/resource_quotable/quota/create.js.erb
263
+ - app/views/resource_quotable/quota/destroy.js.erb
264
+ - app/views/resource_quotable/quota/edit.html.erb
265
+ - app/views/resource_quotable/quota/edit.js.erb
266
+ - app/views/resource_quotable/quota/index.html.erb
267
+ - app/views/resource_quotable/quota/index.js.erb
268
+ - app/views/resource_quotable/quota/index/_row.html.erb
269
+ - app/views/resource_quotable/quota/index/_row_content.html.erb
270
+ - app/views/resource_quotable/quota/new.html.erb
271
+ - app/views/resource_quotable/quota/new.js.erb
272
+ - app/views/resource_quotable/quota/show.html.erb
273
+ - app/views/resource_quotable/quota/show.js.erb
274
+ - app/views/resource_quotable/quota/show/_row.html.erb
275
+ - app/views/resource_quotable/quota/show/_row_content.html.erb
276
+ - app/views/resource_quotable/quota/update.js.erb
277
+ - app/views/resource_quotable/quotum_trackers/index/_row_content.html.erb
278
+ - app/views/resource_quotable/quotum_trackers/reset.js.erb
279
+ - config/routes.rb
280
+ - db/migrate/20220805102601_create_resource_quotable_quota.rb
281
+ - db/migrate/20220811072023_create_resource_quotable_quotum_trackers.rb
282
+ - lib/concerns/controllers/allowed_to_manage_quota_check.rb
283
+ - lib/concerns/models/act_as_quota_trackable.rb
284
+ - lib/concerns/models/act_as_quotable.rb
285
+ - lib/resource_quotable.rb
286
+ - lib/resource_quotable/engine.rb
287
+ - lib/resource_quotable/exeptions.rb
288
+ - lib/resource_quotable/generators/views_generator.rb
289
+ - lib/resource_quotable/helper.rb
290
+ - lib/resource_quotable/version.rb
291
+ - lib/tasks/resource_quotable_tasks.rake
292
+ homepage: https://bitbucket.org/angel_arancibia/resource_quotable/src/master/
293
+ licenses:
294
+ - MIT
295
+ metadata:
296
+ homepage_uri: https://bitbucket.org/angel_arancibia/resource_quotable/src/master/
297
+ source_code_uri: https://bitbucket.org/angel_arancibia/resource_quotable/src/master/
298
+ changelog_uri: https://bitbucket.org/angel_arancibia/resource_quotable/src/master//CHANGELOG.md
299
+ rubygems_mfa_required: 'true'
300
+ post_install_message: 'Please see https://bitbucket.org/angel_arancibia/resource_quotable/src/master/Changelog.md
301
+ for details on how to finish the setup.
302
+
303
+ '
304
+ rdoc_options: []
305
+ require_paths:
306
+ - lib
307
+ required_ruby_version: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: '2.7'
312
+ required_rubygems_version: !ruby/object:Gem::Requirement
313
+ requirements:
314
+ - - ">="
315
+ - !ruby/object:Gem::Version
316
+ version: '0'
317
+ requirements: []
318
+ rubygems_version: 3.1.6
319
+ signing_key:
320
+ specification_version: 4
321
+ summary: Quota system for resource
322
+ test_files: []