mime_actor 0.3.3 → 0.5.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35c75654432a3dd52002da0a92b31560432709c940143b6da12d6c8381298cd5
4
- data.tar.gz: 7a412d03ba99cc45ea2aceb4c3741a49b2bcbc53b04f2a627267e415c4e0955a
3
+ metadata.gz: 21576d34311aa9a06ac9542d118390900d8b9e3d9860fb6ed7d1a4a9b672bf96
4
+ data.tar.gz: a2ca714375f7892e1506bf55b5fcdbbaa3b1ea7884b9f2ad7a1b4284d3fed08a
5
5
  SHA512:
6
- metadata.gz: db971845e8bd7544fea9b7bc711c9e290948eaeaf52526b49e72cab85023d6b8087f1f131c4f5f6ed70591ad342bfab94a09e44f3a9f6d250df6bd3c7d30b72e
7
- data.tar.gz: 0014236f7f1720f88f6bbb7e807c0d34760786b5febc1037d3f871c0b0f2a67d976c4ccadf58d939bff563b5c214bc25ca2160669590050bf6e0ca14c975ae1e
6
+ metadata.gz: c24629937c5b2d7626588b1ef8ffa1d334450bda5dafe90693d0c65bfc5200d8122e0fdbd315206538c85cb6d8aae29eedf7f07289b3971a13f0a6903d757c0b
7
+ data.tar.gz: 07d9061ef2e41f55b0e5e9718f9a719a4da2309232be87bf59f638e2a0f9502cfbcdaa6f054f9e2764b9c9b5a9bb1cd5a3a8544a6844902d5dd1f72d07b8ea1f
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ rubocop:
2
+ enabled: false
data/.rubocop.yml CHANGED
@@ -7,6 +7,7 @@ AllCops:
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - bin/*
10
+ - vendor/**/*
10
11
 
11
12
  Style/Documentation:
12
13
  Enabled: false
@@ -15,6 +16,19 @@ Style/BlockComments:
15
16
  Exclude:
16
17
  - spec/*_helper.rb
17
18
 
19
+ Metrics/AbcSize:
20
+ Enabled: false
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Enabled: false
24
+
25
+ Metrics/PerceivedComplexity:
26
+ Enabled: false
27
+
28
+ Metrics/MethodLength:
29
+ CountAsOne: ['array', 'heredoc', 'method_call']
30
+ Max: 15
31
+
18
32
  Style/StringLiterals:
19
33
  EnforcedStyle: double_quotes
20
34
 
@@ -32,7 +46,14 @@ Layout/HashAlignment:
32
46
  EnforcedColonStyle: table
33
47
 
34
48
  RSpec/MultipleExpectations:
35
- Enabled: false
49
+ Max: 6
36
50
 
37
51
  RSpec/ExampleLength:
38
- Enabled: false
52
+ CountAsOne: ['array', 'heredoc', 'method_call']
53
+ Max: 10
54
+
55
+ RSpec/MultipleMemoizedHelpers:
56
+ Max: 10
57
+
58
+ RSpec/NestedGroups:
59
+ Max: 5
data/README.md CHANGED
@@ -1,25 +1,89 @@
1
1
  # mime_actor
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/mime_actor.svg)](https://badge.fury.io/rb/mime_actor)
3
+ [![Gem Version](https://badge.fury.io/rb/mime_actor.png)](https://badge.fury.io/rb/mime_actor)
4
+ [![codecov](https://codecov.io/gh/ryancyq/mime_actor/graph/badge.svg?token=4C091RHXC3)](https://codecov.io/gh/ryancyq/mime_actor)
4
5
  [![Build](https://github.com/ryancyq/mime_actor/actions/workflows/build.yml/badge.svg)](https://github.com/ryancyq/mime_actor/actions/workflows/build.yml)
5
6
 
6
- Action rendering and rescue with mime type via configuration in actionpack
7
+ Render + Rescue handlers for different MIME types in Rails
7
8
 
8
- ## Installation
9
+ ## Usage
9
10
 
10
- Install the gem and add to the application's Gemfile by executing:
11
+ MimeActor allows you to do something like below:
12
+ ```rb
13
+ class EventsController < ActionController::Base
14
+ # AbstractController::Callbacks here to load model with params
15
+ before_action only: :index { @events = Event.all }
16
+ before_action only: [:show, :update] { @event = Event.find(params.require(:event_id)) }
11
17
 
12
- $ bundle add mime_actor
18
+ compose_scene :html, :json, on: :index
19
+ compose_scene :html, :json, on: [:show, :update]
13
20
 
14
- If bundler is not being used to manage dependencies, install the gem by executing:
21
+ rescue_actor_from ActiveRecord::RecordNotFound, format: :json do |ex|
22
+ render status: :bad_request, json: { error: "Resouce not found" }
23
+ end
24
+
25
+ rescue_actor_from ActiveRecord::RecordNotFound, format: :html, action: :show do |ex|
26
+ redirect_to events_path
27
+ end
28
+
29
+ def index_html
30
+ @event_categories = EventCategory.all
31
+ render :index # render html using @events and @event_categories
32
+ end
33
+
34
+ def index_json
35
+ render json: @events # render json using #as_json
36
+ end
37
+
38
+ def show_html
39
+ render :show # render html using @event
40
+ end
41
+
42
+ def update_html
43
+ redirect_to event_path(@event.id) # redirect to show upon sucessful update
44
+ rescue ActiveRecord::RecordNotFound
45
+ render :edit
46
+ end
47
+
48
+ def show_json
49
+ render json: @event # render json using #as_json
50
+ end
15
51
 
16
- $ gem install mime_actor
52
+ def update_json
53
+ # ...
54
+ render json: @event # render json using #as_json
55
+ end
56
+ end
57
+ ```
17
58
 
18
- ## Getting Started
59
+ ## Features
60
+
61
+ - Action customisation for ActionController per MIME type
62
+ - Customisation are deduplicated automatically when configured multiple times
63
+ - Flexible rescue handler definition for the combination of Action/MIME type or both
64
+ - Built on top of `ActionController::Metal::MimeResponds`
65
+ - Fully compatible with other `ActionController` functionalities
66
+
67
+ ## Requirements
68
+
69
+ - Ruby: MRI 3.1+
70
+ - Rails: 5.0+
71
+
72
+ ## Installation
73
+
74
+ Install the gem and add to the application's Gemfile by executing:
75
+ ```sh
76
+ bundle add mime_actor
77
+ ```
78
+
79
+ If bundler is not being used to manage dependencies, install the gem by executing:
80
+ ```sh
81
+ gem install mime_actor
82
+ ```
19
83
 
20
84
  ## Development
21
85
 
22
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
23
87
 
24
88
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
25
89
 
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mime_actor/scene"
4
+ require "mime_actor/stage"
5
+ require "mime_actor/rescue"
6
+
7
+ require "active_support/concern"
8
+ require "active_support/lazy_load_hooks"
9
+ require "abstract_controller/rendering"
10
+ require "action_controller/metal/mime_responds"
11
+
12
+ module MimeActor
13
+ module Action
14
+ extend ActiveSupport::Concern
15
+
16
+ include AbstractController::Rendering # required by MimeResponds
17
+ include ActionController::MimeResponds
18
+
19
+ include Scene
20
+ include Stage
21
+ include Rescue
22
+ include Logging
23
+
24
+ def start_scene(action)
25
+ action = action&.to_sym
26
+ formats = acting_scenes.fetch(action, Set.new)
27
+
28
+ if formats.empty?
29
+ logger.warn { "format is empty for action :#{action}" }
30
+ return
31
+ end
32
+
33
+ respond_to do |collector|
34
+ formats.each do |format|
35
+ dispatch = self.class.dispatch_cue(action: action, format: format, context: self) do
36
+ cue_actor("#{action}_#{format}")
37
+ end
38
+ collector.public_send(format, &dispatch)
39
+ end
40
+ end
41
+ end
42
+
43
+ ActiveSupport.run_load_hooks(:mime_actor, self)
44
+ end
45
+ end
@@ -1,20 +1,45 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "set"
4
+
3
5
  module MimeActor
4
6
  class Error < StandardError
7
+ def inspect
8
+ "<#{self.class.name}> #{message}"
9
+ end
10
+
11
+ def generate_message
12
+ self.class.name
13
+ end
5
14
  end
6
15
 
7
- class ActorNotFound < Error
16
+ class ActorError < Error
8
17
  attr_reader :actor
9
18
 
10
19
  def initialize(actor)
11
20
  @actor = actor
21
+ super(generate_message)
22
+ end
23
+ end
12
24
 
13
- super(":#{actor} not found")
25
+ class ActorNotFound < ActorError
26
+ def generate_message
27
+ ":#{actor} not found"
14
28
  end
29
+ end
15
30
 
16
- def inspect
17
- "<#{self.class.name}> #{message}"
31
+ class ActionError < Error
32
+ attr_reader :action
33
+
34
+ def initialize(action = nil)
35
+ @action = action
36
+ super(generate_message)
37
+ end
38
+ end
39
+
40
+ class ActionExisted < ActionError
41
+ def generate_message
42
+ "action :#{action} already existed"
18
43
  end
19
44
  end
20
45
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "active_support/configurable"
5
+ require "active_support/isolated_execution_state" # required by active_support/logger
6
+ require "active_support/logger"
7
+ require "active_support/tagged_logging"
8
+
9
+ module MimeActor
10
+ module Logging
11
+ extend ActiveSupport::Concern
12
+
13
+ include ActiveSupport::Configurable
14
+
15
+ included do
16
+ config_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))
17
+ end
18
+
19
+ private
20
+
21
+ def fill_run_sheet(*scenes, &)
22
+ return yield unless logger.respond_to?(:tagged)
23
+
24
+ scenes.unshift "MimeActor" unless logger.formatter.current_tags.include?("MimeActor")
25
+
26
+ logger.tagged(*scenes, &)
27
+ end
28
+ end
29
+ end
@@ -1,56 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "mime_actor/stage"
4
+ require "mime_actor/validator"
5
+
3
6
  require "active_support/concern"
4
7
  require "active_support/core_ext/array/wrap"
5
8
  require "active_support/core_ext/module/attribute_accessors"
6
- require "active_support/core_ext/object/blank"
7
9
  require "active_support/core_ext/string/inflections"
8
- require "set" # remove when ruby > 3,1
9
- require "action_dispatch/http/mime_type"
10
10
 
11
11
  module MimeActor
12
12
  module Rescue
13
13
  extend ActiveSupport::Concern
14
14
 
15
+ include Stage
16
+ include Validator
17
+
15
18
  included do
16
19
  mattr_accessor :actor_rescuers, instance_writer: false, default: []
17
20
  end
18
21
 
19
22
  module ClassMethods
20
23
  def rescue_actor_from(*klazzes, action: nil, format: nil, with: nil, &block)
21
- raise ArgumentError, "Error filter can't be empty" if klazzes.empty?
22
- raise ArgumentError, "Provide only the with: keyword argument or a block" if with.present? && block_given?
23
- raise ArgumentError, "Provide the with: keyword argument or a block" unless with.present? || block_given?
24
+ raise ArgumentError, "error filter is required" if klazzes.empty?
24
25
 
26
+ validate!(:with, with, block)
25
27
  with = block if block_given?
26
- raise ArgumentError, "Rescue handler can only be Symbol/Proc" unless with.is_a?(Proc) || with.is_a?(Symbol)
27
28
 
28
- if format.present?
29
- case format
30
- when Symbol
31
- raise ArgumentError, "Unsupported format: #{format}" unless Mime::SET.symbols.include?(format.to_sym)
32
- when Enumerable
33
- unfiltered = format.to_set
34
- filtered = unfiltered & Mime::SET.symbols.to_set
35
- rejected = unfiltered - filtered
36
- raise ArgumentError, "Unsupported formats: #{rejected.join(", ")}" if rejected.size.positive?
29
+ if action.present?
30
+ if action.is_a?(Enumerable)
31
+ validate!(:actions, action)
37
32
  else
38
- raise ArgumentError, "Format filter can only be Symbol/Enumerable"
33
+ validate!(:action, action)
39
34
  end
40
35
  end
41
36
 
42
- if action.present? && !(action.is_a?(Symbol) || action.is_a?(Enumerable))
43
- raise ArgumentError, "Action filter can only be Symbol/Enumerable"
37
+ if format.present?
38
+ if format.is_a?(Enumerable)
39
+ validate!(:formats, format)
40
+ else
41
+ validate!(:format, format)
42
+ end
44
43
  end
45
44
 
46
45
  klazzes.each do |klazz|
47
- error = if klazz.is_a?(Module)
46
+ error = case klazz
47
+ when Module
48
48
  klazz.name
49
- elsif klazz.is_a?(String)
49
+ when String
50
50
  klazz
51
51
  else
52
- raise ArgumentError,
53
- "#{klazz.inspect} must be a class/module or a String referencing a class/module"
52
+ message = "#{klazz.inspect} must be a Class/Module or a String referencing a Class/Module"
53
+ raise ArgumentError, message
54
54
  end
55
55
 
56
56
  # append at the end because strategies are read in reverse.
@@ -59,12 +59,13 @@ module MimeActor
59
59
  end
60
60
 
61
61
  def rescue_actor(error, action: nil, format: nil, context: self, visited: [])
62
- visited << error
62
+ return if visited.include?(error)
63
63
 
64
+ visited << error
64
65
  if (rescuer = dispatch_rescuer(error, format:, action:, context:))
65
66
  rescuer.call(error, format, action)
66
67
  error
67
- elsif error&.cause && !visited.include?(error.cause)
68
+ elsif error&.cause
68
69
  rescue_actor(error.cause, format:, action:, context:, visited:)
69
70
  end
70
71
  end
@@ -1,52 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "mime_actor/stage"
3
+ require "mime_actor/errors"
4
+ require "mime_actor/validator"
4
5
 
5
6
  require "active_support/concern"
6
7
  require "active_support/core_ext/array/extract_options"
7
8
  require "active_support/core_ext/array/wrap"
8
- require "active_support/core_ext/hash/indifferent_access"
9
9
  require "active_support/core_ext/module/attribute_accessors"
10
- require "set" # remove when ruby > 3,1
11
- require "action_dispatch/http/mime_type"
12
10
 
13
11
  module MimeActor
14
12
  module Scene
15
13
  extend ActiveSupport::Concern
16
14
 
17
- include Stage
15
+ include Validator
18
16
 
19
17
  included do
20
- mattr_accessor :acting_scenes, instance_writer: false, default: ActiveSupport::HashWithIndifferentAccess.new
18
+ mattr_accessor :acting_scenes, instance_writer: false, default: {}
21
19
  end
22
20
 
23
21
  module ClassMethods
24
22
  def compose_scene(*options)
25
23
  config = options.extract_options!
26
- actions = Array.wrap(config[:on])
27
-
28
- raise ArgumentError, "Action name can't be empty, e.g. on: :create" if actions.empty?
29
-
30
- options.each do |mime_type|
31
- raise ArgumentError, "Unsupported format: #{mime_type}" unless Mime::SET.symbols.include?(mime_type.to_sym)
24
+ validate!(:formats, options)
25
+
26
+ actions = config[:on]
27
+ if !actions
28
+ raise ArgumentError, "action is required"
29
+ elsif actions.is_a?(Enumerable)
30
+ validate!(:actions, actions)
31
+ else
32
+ validate!(:action, actions)
33
+ end
32
34
 
33
- actions.each do |action|
34
- if !acting_scenes.key?(action) && actor?(action)
35
- raise ArgumentError, "Action method already defined: #{action}"
36
- end
35
+ options.each do |format|
36
+ Array.wrap(actions).each do |action|
37
+ action_defined = (instance_methods + private_instance_methods).include?(action.to_sym)
38
+ raise MimeActor::ActionExisted, action if !acting_scenes.key?(action) && action_defined
37
39
 
38
40
  acting_scenes[action] ||= Set.new
39
- acting_scenes[action] |= [mime_type.to_sym]
41
+ acting_scenes[action] |= [format]
40
42
 
41
- next if actor?(action)
43
+ next if action_defined
42
44
 
43
45
  class_eval(
44
46
  # def index
45
- # self.cue_actor(:play_scene, :index)
47
+ # self.respond_to?(:start_scene) && self.start_scene(:index)
46
48
  # end
47
49
  <<-RUBY, __FILE__, __LINE__ + 1
48
50
  def #{action}
49
- self.cue_actor(:play_scene, :#{action})
51
+ self.respond_to?(:start_scene) && self.start_scene(:#{action})
50
52
  end
51
53
  RUBY
52
54
  )
@@ -1,18 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "mime_actor/errors"
4
+ require "mime_actor/logging"
4
5
 
5
6
  require "active_support/concern"
6
- require "active_support/configurable"
7
7
  require "active_support/core_ext/module/attribute_accessors"
8
- require "abstract_controller/logger"
9
8
 
10
9
  module MimeActor
11
10
  module Stage
12
11
  extend ActiveSupport::Concern
13
12
 
14
- include ActiveSupport::Configurable
15
- include AbstractController::Logger
13
+ include Logging
16
14
 
17
15
  included do
18
16
  mattr_accessor :raise_on_missing_actor, instance_writer: false, default: false
@@ -20,29 +18,31 @@ module MimeActor
20
18
 
21
19
  module ClassMethods
22
20
  def actor?(actor_name)
23
- return action_methods.include?(actor_name.to_s) if singleton_methods.include?(:action_methods)
24
-
25
- instance_methods.include?(actor_name.to_sym)
21
+ # exclude public methods from ancestors
22
+ found = public_instance_methods(false).include?(actor_name.to_sym)
23
+ # exclude private methods from ancestors
24
+ if !found && private_instance_methods(false).include?(actor_name.to_sym)
25
+ logger.debug { "actor must be public method, #{actor_name} is private method" }
26
+ end
27
+ found
26
28
  end
27
- end
28
-
29
- def actor?(actor_name)
30
- return action_methods.include?(actor_name.to_s) if respond_to?(:action_methods)
31
-
32
- methods.include?(actor_name.to_sym)
33
- end
34
29
 
35
- def find_actor(actor_name)
36
- return method(actor_name) if actor?(actor_name)
37
-
38
- error = MimeActor::ActorNotFound.new(actor_name)
39
- raise error if raise_on_missing_actor
40
-
41
- logger.warn { "Actor not found: #{error.inspect}" }
30
+ def dispatch_cue(action: nil, format: nil, context: self, &block)
31
+ lambda do
32
+ context.instance_exec(&block)
33
+ rescue StandardError => e
34
+ (respond_to?(:rescue_actor) && rescue_actor(e, action:, format:, context:)) || raise
35
+ end
36
+ end
42
37
  end
43
38
 
44
39
  def cue_actor(actor_name, *args)
45
- return unless actor?(actor_name)
40
+ unless self.class.actor?(actor_name)
41
+ raise MimeActor::ActorNotFound, actor_name if raise_on_missing_actor
42
+
43
+ logger.warn { "actor not found, expected :#{actor_name}" }
44
+ return
45
+ end
46
46
 
47
47
  result = public_send(actor_name, *args)
48
48
  if block_given?
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "set" # required by mime_type with ruby <= 3.1
5
+ require "action_dispatch/http/mime_type"
6
+
7
+ module MimeActor
8
+ module Validator
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ mattr_accessor :scene_formats, instance_writer: false, default: Mime::SET.symbols.to_set
13
+ end
14
+
15
+ module ClassMethods
16
+ def validate!(rule, *args)
17
+ validator = "validate_#{rule}"
18
+ raise NameError, "Validator not found, got: #{validator}" unless respond_to?(validator, true)
19
+
20
+ error = send(validator, *args)
21
+ raise error if error
22
+ end
23
+
24
+ def validate_action(unchecked)
25
+ ArgumentError.new("action must be a Symbol") unless unchecked.is_a?(Symbol)
26
+ end
27
+
28
+ def validate_actions(unchecked)
29
+ rejected = unchecked.reject { |action| action.is_a?(Symbol) }
30
+ NameError.new("invalid actions, got: #{rejected.join(", ")}") if rejected.size.positive?
31
+ end
32
+
33
+ def validate_format(unchecked)
34
+ return ArgumentError.new("format must be a Symbol") unless unchecked.is_a?(Symbol)
35
+
36
+ NameError.new("invalid format, got: #{unchecked}") unless scene_formats.include?(unchecked)
37
+ end
38
+
39
+ def validate_formats(unchecked)
40
+ unfiltered = unchecked.to_set
41
+ filtered = unfiltered & scene_formats
42
+ rejected = unfiltered - filtered
43
+
44
+ NameError.new("invalid formats, got: #{rejected.join(", ")}") if rejected.size.positive?
45
+ end
46
+
47
+ def validate_with(unchecked, block)
48
+ if unchecked.present? && block.present?
49
+ return ArgumentError.new("provide either the with: keyword argument or a block")
50
+ end
51
+ unless unchecked.present? || block.present?
52
+ return ArgumentError.new("provide the with: keyword argument or a block")
53
+ end
54
+
55
+ return if block.present?
56
+ return if unchecked.is_a?(Proc) || unchecked.is_a?(Symbol)
57
+
58
+ ArgumentError.new("with handler must be a Symbol or Proc, got: #{unchecked.inspect}")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -11,8 +11,8 @@ module MimeActor
11
11
 
12
12
  module VERSION
13
13
  MAJOR = 0
14
- MINOR = 3
15
- BUILD = 3
14
+ MINOR = 5
15
+ BUILD = 1
16
16
  PRE = nil
17
17
 
18
18
  STRING = [MAJOR, MINOR, BUILD, PRE].compact.join(".")
data/lib/mime_actor.rb CHANGED
@@ -8,8 +8,10 @@ require "active_support/dependencies/autoload"
8
8
  module MimeActor
9
9
  extend ActiveSupport::Autoload
10
10
 
11
- autoload :Act
11
+ autoload :Action
12
12
  autoload :Scene
13
13
  autoload :Stage
14
14
  autoload :Rescue
15
+ autoload :Validator
16
+ autoload :Logging
15
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mime_actor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Chang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-24 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".hound.yml"
62
63
  - ".rspec"
63
64
  - ".rubocop.yml"
64
65
  - ".ruby-version"
@@ -66,11 +67,13 @@ files:
66
67
  - README.md
67
68
  - Rakefile
68
69
  - lib/mime_actor.rb
69
- - lib/mime_actor/act.rb
70
+ - lib/mime_actor/action.rb
70
71
  - lib/mime_actor/errors.rb
72
+ - lib/mime_actor/logging.rb
71
73
  - lib/mime_actor/rescue.rb
72
74
  - lib/mime_actor/scene.rb
73
75
  - lib/mime_actor/stage.rb
76
+ - lib/mime_actor/validator.rb
74
77
  - lib/mime_actor/version.rb
75
78
  - sig/mime_actor.rbs
76
79
  homepage: https://github.com/ryancyq/mime_actor
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "mime_actor/scene"
4
- require "mime_actor/stage"
5
- require "mime_actor/rescue"
6
-
7
- require "active_support/concern"
8
- require "abstract_controller/rendering"
9
- require "action_controller/metal/mime_responds"
10
-
11
- module MimeActor
12
- module Act
13
- extend ActiveSupport::Concern
14
-
15
- include AbstractController::Rendering # required by MimeResponds
16
- include ActionController::MimeResponds
17
- include Scene
18
- include Stage
19
- include Rescue
20
-
21
- module ClassMethods
22
- def dispatch_act(action: nil, format: nil, context: self, &block)
23
- lambda do
24
- context.instance_exec(&block)
25
- rescue StandardError => e
26
- (respond_to?(:rescue_actor) && rescue_actor(e, action:, format:, context:)) || raise
27
- end
28
- end
29
- end
30
-
31
- private
32
-
33
- def play_scene(action)
34
- action = action&.to_sym
35
- return unless acting_scenes.key?(action)
36
-
37
- mime_types = acting_scenes.fetch(action, Set.new)
38
- respond_to do |collector|
39
- mime_types.each do |mime_type|
40
- next unless (actor = find_actor("#{action}_#{mime_type}"))
41
-
42
- dispatch = self.class.dispatch_act(
43
- action: action,
44
- format: mime_type,
45
- context: self,
46
- &actor
47
- )
48
- collector.public_send(mime_type, &dispatch)
49
- end
50
- end
51
- end
52
- end
53
- end