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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f099315434127b3b7044aad85eca2f69664521753dd339af0f8b6829e0ef8dc
4
- data.tar.gz: f8d79ab0813b5f3d63a8a991c9a0f39f328cc67e991738a21030a7fcaee3eae6
3
+ metadata.gz: 21576d34311aa9a06ac9542d118390900d8b9e3d9860fb6ed7d1a4a9b672bf96
4
+ data.tar.gz: a2ca714375f7892e1506bf55b5fcdbbaa3b1ea7884b9f2ad7a1b4284d3fed08a
5
5
  SHA512:
6
- metadata.gz: ba11f403b7031051f9d56577a34dc7b2c63906aabe7b6e663fa9ef87225e0a9334d3a9f08eabbefc5f85a201c8ed73e231e4c616a2f0bac7d1a37e05607a4e81
7
- data.tar.gz: 3f21642e23e14ef5a175740e7916618ed3fb99b8395197d7b5239abe0ead83d0ea498ed1b6f63fa4830e9803e2bc16c04f32c43b25544bcf57c9986f2999f528
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
data/README.md CHANGED
@@ -1,25 +1,89 @@
1
1
  # mime_actor
2
2
 
3
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
 
@@ -10,7 +10,7 @@ require "abstract_controller/rendering"
10
10
  require "action_controller/metal/mime_responds"
11
11
 
12
12
  module MimeActor
13
- module Act
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, action: #{action}" }
29
+ logger.warn { "format is empty for action :#{action}" }
30
30
  return
31
31
  end
32
32
 
@@ -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, got: #{actor_name}" }
43
+ logger.warn { "actor not found, expected :#{actor_name}" }
44
44
  return
45
45
  end
46
46
 
@@ -11,8 +11,8 @@ module MimeActor
11
11
 
12
12
  module VERSION
13
13
  MAJOR = 0
14
- MINOR = 4
15
- BUILD = 0
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,7 +8,7 @@ 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
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.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-27 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,7 +67,7 @@ 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
71
72
  - lib/mime_actor/logging.rb
72
73
  - lib/mime_actor/rescue.rb