active_shrine 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -14
- data/Rakefile +2 -8
- data/config.ru +9 -0
- data/lib/.DS_Store +0 -0
- data/lib/active_shrine/attached/base.rb +24 -0
- data/lib/active_shrine/attached/changes/create_many.rb +45 -0
- data/lib/active_shrine/attached/changes/create_one.rb +51 -0
- data/lib/active_shrine/attached/changes/create_one_of_many.rb +17 -0
- data/lib/active_shrine/attached/changes/delete_many.rb +28 -0
- data/lib/active_shrine/attached/changes/delete_one.rb +24 -0
- data/lib/active_shrine/attached/changes/detach_many.rb +24 -0
- data/lib/active_shrine/attached/changes/detach_one.rb +31 -0
- data/lib/active_shrine/attached/changes/purge_many.rb +34 -0
- data/lib/active_shrine/attached/changes/purge_one.rb +34 -0
- data/lib/active_shrine/attached/changes.rb +24 -0
- data/lib/active_shrine/attached/many.rb +78 -0
- data/lib/active_shrine/attached/one.rb +90 -0
- data/lib/active_shrine/attached.rb +14 -0
- data/lib/active_shrine/attachment.rb +111 -0
- data/lib/active_shrine/job/destroy_shrine_attachment.rb +18 -0
- data/lib/active_shrine/job/promote_shrine_attachment.rb +21 -0
- data/lib/active_shrine/job.rb +12 -0
- data/lib/active_shrine/model.rb +200 -0
- data/lib/active_shrine/railtie.rb +11 -0
- data/lib/active_shrine/reflection.rb +75 -0
- data/lib/active_shrine/version.rb +5 -0
- data/lib/active_shrine.rb +18 -0
- data/lib/generators/.DS_Store +0 -0
- data/lib/generators/active_shrine/install/install_generator.rb +29 -0
- data/lib/generators/active_shrine/install/templates/app/jobs/destroy_shrine_attachment_job.rb +5 -0
- data/lib/generators/active_shrine/install/templates/app/jobs/promote_shrine_attachment_job.rb +5 -0
- data/lib/generators/active_shrine/install/templates/config/initializers/shrine.rb +51 -0
- data/lib/generators/active_shrine/install/templates/db/migrate/create_active_shrine_attachments.rb +28 -0
- data/sig/active_shrine.rbs +4 -0
- metadata +115 -47
- data/MIT-LICENSE +0 -20
- data/app/assets/config/api_base_manifest.js +0 -1
- data/app/assets/stylesheets/api_base/application.css +0 -15
- data/app/controllers/api_base/application_controller.rb +0 -6
- data/app/helpers/api_base/application_helper.rb +0 -6
- data/app/jobs/api_base/application_job.rb +0 -6
- data/app/mailers/api_base/application_mailer.rb +0 -8
- data/app/models/api_base/api_log.rb +0 -108
- data/app/models/api_base/application_record.rb +0 -7
- data/app/views/layouts/api_base/application.html.erb +0 -15
- data/config/routes.rb +0 -4
- data/db/migrate/20220612165032_create_api_logs.rb +0 -22
- data/lib/api_base/behaviours/get_json.rb +0 -26
- data/lib/api_base/behaviours/post_json.rb +0 -27
- data/lib/api_base/behaviours/shared.rb +0 -51
- data/lib/api_base/concerns/filterer.rb +0 -47
- data/lib/api_base/concerns/traceable.rb +0 -25
- data/lib/api_base/connection.rb +0 -24
- data/lib/api_base/endpoint.rb +0 -65
- data/lib/api_base/engine.rb +0 -7
- data/lib/api_base/errors/api_error.rb +0 -8
- data/lib/api_base/errors/processing_error.rb +0 -8
- data/lib/api_base/service.rb +0 -17
- data/lib/api_base/version.rb +0 -5
- data/lib/api_base.rb +0 -14
- 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
|
data/lib/api_base/connection.rb
DELETED
@@ -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
|
data/lib/api_base/endpoint.rb
DELETED
@@ -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
|
data/lib/api_base/engine.rb
DELETED
data/lib/api_base/service.rb
DELETED
@@ -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
|
data/lib/api_base/version.rb
DELETED
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
|