mime_actor 0.4.0 → 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 +4 -4
- data/.hound.yml +2 -0
- data/.rubocop.yml +1 -0
- data/README.md +72 -8
- data/lib/mime_actor/{act.rb → action.rb} +2 -2
- data/lib/mime_actor/stage.rb +1 -1
- data/lib/mime_actor/version.rb +2 -2
- data/lib/mime_actor.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21576d34311aa9a06ac9542d118390900d8b9e3d9860fb6ed7d1a4a9b672bf96
|
4
|
+
data.tar.gz: a2ca714375f7892e1506bf55b5fcdbbaa3b1ea7884b9f2ad7a1b4284d3fed08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c24629937c5b2d7626588b1ef8ffa1d334450bda5dafe90693d0c65bfc5200d8122e0fdbd315206538c85cb6d8aae29eedf7f07289b3971a13f0a6903d757c0b
|
7
|
+
data.tar.gz: 07d9061ef2e41f55b0e5e9718f9a719a4da2309232be87bf59f638e2a0f9502cfbcdaa6f054f9e2764b9c9b5a9bb1cd5a3a8544a6844902d5dd1f72d07b8ea1f
|
data/.hound.yml
ADDED
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,25 +1,89 @@
|
|
1
1
|
# mime_actor
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/mime_actor)
|
4
|
+
[](https://codecov.io/gh/ryancyq/mime_actor)
|
4
5
|
[](https://github.com/ryancyq/mime_actor/actions/workflows/build.yml)
|
5
6
|
|
6
|
-
|
7
|
+
Render + Rescue handlers for different MIME types in Rails
|
7
8
|
|
8
|
-
##
|
9
|
+
## Usage
|
9
10
|
|
10
|
-
|
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
|
-
|
18
|
+
compose_scene :html, :json, on: :index
|
19
|
+
compose_scene :html, :json, on: [:show, :update]
|
13
20
|
|
14
|
-
|
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
|
-
|
52
|
+
def update_json
|
53
|
+
# ...
|
54
|
+
render json: @event # render json using #as_json
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
17
58
|
|
18
|
-
##
|
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
|
|
@@ -10,7 +10,7 @@ require "abstract_controller/rendering"
|
|
10
10
|
require "action_controller/metal/mime_responds"
|
11
11
|
|
12
12
|
module MimeActor
|
13
|
-
module
|
13
|
+
module Action
|
14
14
|
extend ActiveSupport::Concern
|
15
15
|
|
16
16
|
include AbstractController::Rendering # required by MimeResponds
|
@@ -26,7 +26,7 @@ module MimeActor
|
|
26
26
|
formats = acting_scenes.fetch(action, Set.new)
|
27
27
|
|
28
28
|
if formats.empty?
|
29
|
-
logger.warn { "format is empty
|
29
|
+
logger.warn { "format is empty for action :#{action}" }
|
30
30
|
return
|
31
31
|
end
|
32
32
|
|
data/lib/mime_actor/stage.rb
CHANGED
@@ -40,7 +40,7 @@ module MimeActor
|
|
40
40
|
unless self.class.actor?(actor_name)
|
41
41
|
raise MimeActor::ActorNotFound, actor_name if raise_on_missing_actor
|
42
42
|
|
43
|
-
logger.warn { "actor not found,
|
43
|
+
logger.warn { "actor not found, expected :#{actor_name}" }
|
44
44
|
return
|
45
45
|
end
|
46
46
|
|
data/lib/mime_actor/version.rb
CHANGED
data/lib/mime_actor.rb
CHANGED
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.
|
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-
|
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,7 +67,7 @@ files:
|
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|
68
69
|
- lib/mime_actor.rb
|
69
|
-
- lib/mime_actor/
|
70
|
+
- lib/mime_actor/action.rb
|
70
71
|
- lib/mime_actor/errors.rb
|
71
72
|
- lib/mime_actor/logging.rb
|
72
73
|
- lib/mime_actor/rescue.rb
|