mime_actor 0.0.0.alpha

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7a7d2b7b38b9bb1238267b58f57961e099fd114c9f4786d3300a1a7e74611bc7
4
+ data.tar.gz: 3266040aa145d6a6fd2188bd9c9f00a5fe0f6b6e9fd1e165634778d53ae6a368
5
+ SHA512:
6
+ metadata.gz: ddb033cca592816fa6f22e05f51d94a3bf67918541ecdef2d24252e3e3d0bea0d00eeb8b69b6ab63f6b08c1cb9e82f73c288883f9d170a34539e78cf0acd0f30
7
+ data.tar.gz: 4014b324249b3f865689426eef1e0314527ef1e8c9bf5d07728b2f3a10fb3c0cdba870fc3a40315e7323a972ab4f04a3193504ba483da37bc19e7eb3e5fbd926
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ryan Chang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # mime_actor
2
+
3
+ Action rendering and rescue with mime type via configuration in actionpack
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add mime_actor
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install mime_actor
14
+
15
+ ## Getting Started
16
+
17
+ ## Development
18
+
19
+ 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.
20
+
21
+ 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).
22
+
23
+ ## License
24
+ Please see [LICENSE](https://github.com/ryancyq/mime_actor/blob/main/LICENSE) for licensing details.
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ryancyq/mime_actor.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rubocop/rake_task"
6
+ RuboCop::RakeTask.new
7
+
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/array/extract_options"
4
+ require "active_support/core_ext/array/wrap"
5
+ require "active_support/core_ext/hash/indifferent_access"
6
+ require 'action_controller'
7
+ require 'action_dispatch'
8
+
9
+ module MimeActor
10
+ module Formatter
11
+ extend ActiveSupport::Concern
12
+ include ActiveSupport::Configurable
13
+ include AbstractController::Logger
14
+ include AbstractController::Rendering # required by MimeResponds
15
+ include ActionController::MimeResponds
16
+
17
+ SUPPORTED_MIME_TYPES = Mime::SET.symbols.to_set
18
+ private_constant :SUPPORTED_MIME_TYPES
19
+
20
+ included do
21
+ mattr_accessor :action_formatters, instance_writer: false, default: ActiveSupport::HashWithIndifferentAccess.new
22
+ mattr_accessor :raise_on_missing_action_formatter, instance_writer: false, default: false
23
+ end
24
+
25
+ module ClassMethods
26
+ def act_on_format(*formats_and_options)
27
+ options = formats_and_options.extract_options!
28
+ actions = Array.wrap(options[:on])
29
+
30
+ message = "Action name can't be blank, e.g. on: :create"
31
+ raise ArgumentError, message if actions.empty?
32
+
33
+ formats_and_options.each do |format|
34
+ message = "Unsupported format: #{format}"
35
+ raise ArgumentError, message unless SUPPORTED_MIME_TYPES.include?(format.to_sym)
36
+
37
+ actions.each do |action|
38
+ message = "Action method already defined: #{action}"
39
+ raise ArgumentError, message if action_methods.include?(action.to_s) && !action_formatters.key?(action)
40
+
41
+ action_formatters[action] ||= Set.new
42
+ action_formatters[action] |= [format]
43
+
44
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
45
+ def #{action}
46
+ perform_act
47
+ end
48
+ RUBY
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def perform_act
57
+ return unless action_formatters.key?(action_name)
58
+
59
+ formatters = action_formatters.fetch(action_name, Set.new)
60
+ respond_to do |collector|
61
+ formatters.each do |formatter|
62
+ next unless actor = find_actor(action_name, formatter)
63
+
64
+ collector.public_send(formatter, &actor)
65
+ end
66
+ end
67
+ end
68
+
69
+ def find_actor(action, format)
70
+ actor_name = "#{action}_#{format}"
71
+
72
+ unless action_methods.include?(actor_name)
73
+ message = "Method: #{actor_name} could not be found for action: #{action_name}, format: #{format}"
74
+ raise AbstractController::ActionNotFound.new(message, self, actor_name) if raise_on_missing_action_formatter
75
+
76
+ logger.warn { message }
77
+ return
78
+ end
79
+
80
+ self.method(actor_name)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MimeActor
4
+ def self.version
5
+ gem_version
6
+ end
7
+
8
+ def self.gem_version
9
+ Gem::Version.new VERSION::STRING
10
+ end
11
+
12
+ module VERSION
13
+ MAJOR = 0
14
+ MINOR = 0
15
+ BUILD = 0
16
+ PRE = "alpha"
17
+
18
+ STRING = [MAJOR, MINOR, BUILD, PRE].compact.join(".")
19
+ end
20
+ end
data/lib/mime_actor.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mime_actor/version"
4
+
5
+ require 'active_support'
6
+
7
+ module MimeActor
8
+ extend ActiveSupport::Concern
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :Formatter
12
+ include Formatter
13
+ end
@@ -0,0 +1,4 @@
1
+ module MimeActor
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mime_actor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Chang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '11.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '11.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionpack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - ryancyq@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".rspec"
91
+ - ".rubocop.yml"
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - lib/mime_actor.rb
96
+ - lib/mime_actor/formatter.rb
97
+ - lib/mime_actor/version.rb
98
+ - sig/mime_actor.rbs
99
+ homepage: https://github.com/ryancyq/mime_actor
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ homepage_uri: https://github.com/ryancyq/mime_actor
105
+ source_code_uri: https://github.com/ryancyq/mime_actor
106
+ changelog_uri: https://github.com/ryancyq/mime_actor/blob/main/CHANGELOG.md
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.7.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.5.9
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: action rendering and rescue with mime type via configuration in actionpack
126
+ test_files: []