active_shrine 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +42 -14
  8. data/Rakefile +2 -8
  9. data/config.ru +9 -0
  10. data/lib/.DS_Store +0 -0
  11. data/lib/active_shrine/attached/base.rb +24 -0
  12. data/lib/active_shrine/attached/changes/create_many.rb +45 -0
  13. data/lib/active_shrine/attached/changes/create_one.rb +51 -0
  14. data/lib/active_shrine/attached/changes/create_one_of_many.rb +17 -0
  15. data/lib/active_shrine/attached/changes/delete_many.rb +28 -0
  16. data/lib/active_shrine/attached/changes/delete_one.rb +24 -0
  17. data/lib/active_shrine/attached/changes/detach_many.rb +24 -0
  18. data/lib/active_shrine/attached/changes/detach_one.rb +31 -0
  19. data/lib/active_shrine/attached/changes/purge_many.rb +34 -0
  20. data/lib/active_shrine/attached/changes/purge_one.rb +34 -0
  21. data/lib/active_shrine/attached/changes.rb +24 -0
  22. data/lib/active_shrine/attached/many.rb +78 -0
  23. data/lib/active_shrine/attached/one.rb +90 -0
  24. data/lib/active_shrine/attached.rb +14 -0
  25. data/lib/active_shrine/attachment.rb +111 -0
  26. data/lib/active_shrine/job/destroy_shrine_attachment.rb +18 -0
  27. data/lib/active_shrine/job/promote_shrine_attachment.rb +21 -0
  28. data/lib/active_shrine/job.rb +12 -0
  29. data/lib/active_shrine/model.rb +200 -0
  30. data/lib/active_shrine/railtie.rb +11 -0
  31. data/lib/active_shrine/reflection.rb +75 -0
  32. data/lib/active_shrine/version.rb +5 -0
  33. data/lib/active_shrine.rb +18 -0
  34. data/lib/generators/.DS_Store +0 -0
  35. data/lib/generators/active_shrine/install/install_generator.rb +29 -0
  36. data/lib/generators/active_shrine/install/templates/app/jobs/destroy_shrine_attachment_job.rb +5 -0
  37. data/lib/generators/active_shrine/install/templates/app/jobs/promote_shrine_attachment_job.rb +5 -0
  38. data/lib/generators/active_shrine/install/templates/config/initializers/shrine.rb +51 -0
  39. data/lib/generators/active_shrine/install/templates/db/migrate/create_active_shrine_attachments.rb +28 -0
  40. data/sig/active_shrine.rbs +4 -0
  41. metadata +120 -47
  42. data/MIT-LICENSE +0 -20
  43. data/app/assets/config/api_base_manifest.js +0 -1
  44. data/app/assets/stylesheets/api_base/application.css +0 -15
  45. data/app/controllers/api_base/application_controller.rb +0 -6
  46. data/app/helpers/api_base/application_helper.rb +0 -6
  47. data/app/jobs/api_base/application_job.rb +0 -6
  48. data/app/mailers/api_base/application_mailer.rb +0 -8
  49. data/app/models/api_base/api_log.rb +0 -108
  50. data/app/models/api_base/application_record.rb +0 -7
  51. data/app/views/layouts/api_base/application.html.erb +0 -15
  52. data/config/routes.rb +0 -4
  53. data/db/migrate/20220612165032_create_api_logs.rb +0 -22
  54. data/lib/api_base/behaviours/get_json.rb +0 -26
  55. data/lib/api_base/behaviours/post_json.rb +0 -27
  56. data/lib/api_base/behaviours/shared.rb +0 -51
  57. data/lib/api_base/concerns/filterer.rb +0 -47
  58. data/lib/api_base/concerns/traceable.rb +0 -25
  59. data/lib/api_base/connection.rb +0 -24
  60. data/lib/api_base/endpoint.rb +0 -65
  61. data/lib/api_base/engine.rb +0 -7
  62. data/lib/api_base/errors/api_error.rb +0 -8
  63. data/lib/api_base/errors/processing_error.rb +0 -8
  64. data/lib/api_base/service.rb +0 -17
  65. data/lib/api_base/version.rb +0 -5
  66. data/lib/api_base.rb +0 -14
  67. data/lib/tasks/api_base_tasks.rake +0 -5
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- module Concerns
5
- module Traceable
6
- protected
7
-
8
- def trace_root_tag(name, value)
9
- Rails.logger.debug "trace_root_tag -> #{name} | #{value}"
10
- end
11
-
12
- def trace_root_error(error)
13
- Rails.logger.debug "trace_root_error -> #{error}"
14
- end
15
-
16
- def trace_active_tag(name, value)
17
- Rails.logger.debug "trace_active_tag -> #{name} | #{value}"
18
- end
19
-
20
- def trace_active_error(error)
21
- Rails.logger.debug "trace_active_error -> #{error}"
22
- end
23
- end
24
- end
25
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- module Connection
5
- def connection
6
- @connection_cache ||= {}
7
- @connection_cache[connection_name] ||= with_connection(connection_name)
8
- end
9
-
10
- def connection_name
11
- defined?(@connection_name) ? @connection_name.to_sym : :default
12
- end
13
-
14
- def with_connection(connection_name)
15
- @connection_name = connection_name
16
- end
17
-
18
- protected
19
-
20
- def with_connection(connection_name)
21
- raise NotImplementedError, "with_connection is not implemented"
22
- end
23
- end
24
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'faraday'
4
- require 'stoplight'
5
- require 'api_base/service'
6
- require 'api_base/connection'
7
- require 'api_base/concerns/traceable'
8
- require 'api_base/concerns/filterer'
9
- require 'api_base/errors/api_error'
10
- require 'api_base/errors/processing_error'
11
-
12
- module ApiBase
13
- class Endpoint
14
- include ActiveSupport::Rescuable
15
- include Concerns::Traceable
16
- include Concerns::Filterer
17
- include ApiBase::Service
18
- include ApiBase::Connection
19
-
20
- rescue_from Stoplight::Error::RedLight do
21
- Rails.logger.warn "#{identifier} api circuit is closed"
22
- raise ApiBase::Errors::ApiError, 'Circuit broken'
23
- end
24
-
25
- rescue_from Faraday::TimeoutError do
26
- Rails.logger.warn "#{identifier} api timed-out"
27
- raise ApiBase::Errors::ApiError, 'Request timed-out'
28
- end
29
-
30
- def identifier
31
- "#{service_name}:#{connection_name}"
32
- end
33
-
34
- protected
35
-
36
- def execute(&block)
37
- light = Stoplight(identifier) do
38
- block.call
39
- end
40
-
41
- light.with_error_handler do |error, handler|
42
- # We don't want processing errors to affect our circuit breakers
43
- # They are our api equivalent of runtime errors.
44
- raise error if error.is_a?(ApiBase::Errors::ProcessingError)
45
-
46
- handler.call(error)
47
- end
48
-
49
- light.run
50
- rescue StandardError => e
51
- trace_active_error(e)
52
- rescue_with_handler(e) || raise
53
- end
54
-
55
- def validate_status_code(response)
56
- return if success_status_codes.include?(response.status)
57
-
58
- raise ApiBase::Errors::ProcessingError, "Request failed with status: #{response.status}"
59
- end
60
-
61
- def filterer
62
- @filterer ||= ActiveSupport::ParameterFilter.new sensitive_keys
63
- end
64
- end
65
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- class Engine < ::Rails::Engine
5
- isolate_namespace ApiBase
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- module Errors
5
- class ApiError < StandardError
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- module Errors
5
- class ProcessingError < ApiError
6
- end
7
- end
8
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- module Service
5
- def service_name
6
- raise NotImplementedError, 'service_name is not implemented'
7
- end
8
-
9
- def sensitive_keys
10
- raise NotImplementedError, 'sensitive_keys is not implemented'
11
- end
12
-
13
- def success_status_codes
14
- [200, 201]
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApiBase
4
- VERSION = '0.1.0'
5
- end
data/lib/api_base.rb DELETED
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'api_base/version'
4
- require 'api_base/engine'
5
- require 'api_base/endpoint'
6
- require 'api_base/behaviours/shared'
7
- require 'api_base/behaviours/get_json'
8
- require 'api_base/behaviours/post_json'
9
- require 'api_base/errors/api_error'
10
- require 'api_base/errors/processing_error'
11
-
12
- module ApiBase
13
- # Your code goes here...
14
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
- # desc "Explaining what the task does"
3
- # task :api_base do
4
- # # Task goes here
5
- # end