inertia_rails 3.3.0 → 3.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 617a4b404988a934d8bfb0ce176965bec8f09d99dcb167322579152597c75261
4
- data.tar.gz: 739e59619439d641ef16dd0816eaab093beb28990624397509a4f1c3b0fc40c6
3
+ metadata.gz: 58d0616b3504cdbe3a0002ea2568b8af2bf8ab442882115109c1c4fcd636fbf2
4
+ data.tar.gz: ad704410b5c41f0c75a6dc6b2029e9e3742ec16539ab607414f86d0c63a7a397
5
5
  SHA512:
6
- metadata.gz: cc2dcfbdc024ea9a3e83bbd7f0d5afb1be1d14e753d776417f4dbfd7f6bd6e3cdc50e307b73d5495a67b8419ed29b4d2863f467bbf858383504bc7e62920e1ea
7
- data.tar.gz: 825b82f4daf26c050c7fe703da03834143a866b2db9728cbb56dface555f4453e984b82038d61bef5e5ce40aa80ef295ef1def1b29794cdc0ef93f6f53a48267
6
+ metadata.gz: b19bade9694bad666820b90e25727658679ce057c06c501f95344d70cbced198ed217d5f965d8146eb303ae48794675e93da9cd371c012afb8965533cf8c9eba
7
+ data.tar.gz: 1a1ce123b90feecc66c211ea38cbcd4a3db6d2696ec0807a0e196baad99b32901d205fefae38497db2eba22d8da7f7dbc8b2923c20474f6626d639e7c033a99d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.4.0] - 2024-11-02
8
+
9
+ * Inertia Rails documentation (@skryukov)
10
+ * Add specs for config refactor (#139)
11
+ * New feature: if/unless/only/except options for inertia_share. Enables per-action sharing! (#137, @skryukov)
12
+ * Bugfix: for inertia errors when using message_pack to serialize cookies. (#143, @BenMorganMY)
13
+ * Test Rails 7.2 in CI/CD (#145, @skryukov)
14
+ * Bring redirect behavior in line with Rails 7.0 behavior (#146, @skryukov)
15
+ * Gemspec cleanup (#149, @skryukov)
16
+
7
17
  ## [3.3.0] - 2024-10-27
8
18
 
9
19
  * Refactor Inertia configuration into a controller class method. Thanks @ElMassimo!
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Based on AbstractController::Callbacks::ActionFilter
4
+ # https://github.com/rails/rails/blob/v7.2.0/actionpack/lib/abstract_controller/callbacks.rb#L39
5
+ module InertiaRails
6
+ class ActionFilter
7
+ def initialize(conditional_key, actions)
8
+ @conditional_key = conditional_key
9
+ @actions = Array(actions).map(&:to_s).to_set
10
+ end
11
+
12
+ def match?(controller)
13
+ missing_action = @actions.find { |action| !controller.available_action?(action) }
14
+ if missing_action
15
+ message = <<~MSG
16
+ The #{missing_action} action could not be found for the :inertia_share
17
+ callback on #{controller.class.name}, but it is listed in the controller's
18
+ #{@conditional_key.inspect} option.
19
+ MSG
20
+
21
+ raise AbstractController::ActionNotFound.new(message, controller, missing_action)
22
+ end
23
+
24
+ @actions.include?(controller.action_name)
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,6 @@
1
1
  require_relative "inertia_rails"
2
2
  require_relative "helper"
3
+ require_relative "action_filter"
3
4
 
4
5
  module InertiaRails
5
6
  module Controller
@@ -14,10 +15,19 @@ module InertiaRails
14
15
  end
15
16
 
16
17
  module ClassMethods
17
- def inertia_share(attrs = {}, &block)
18
- @inertia_share ||= []
19
- @inertia_share << attrs.freeze unless attrs.empty?
20
- @inertia_share << block if block
18
+ def inertia_share(hash = nil, **props, &block)
19
+ options = extract_inertia_share_options(props)
20
+ return push_to_inertia_share(**(hash || props), &block) if options.empty?
21
+
22
+ push_to_inertia_share do
23
+ next unless options[:if].all? { |filter| instance_exec(&filter) } if options[:if]
24
+ next unless options[:unless].none? { |filter| instance_exec(&filter) } if options[:unless]
25
+
26
+ next hash unless block
27
+
28
+ res = instance_exec(&block)
29
+ hash ? hash.merge(res) : res
30
+ end
21
31
  end
22
32
 
23
33
  def inertia_config(**attrs)
@@ -55,6 +65,53 @@ module InertiaRails
55
65
  end.freeze
56
66
  end
57
67
  end
68
+
69
+ private
70
+
71
+ def push_to_inertia_share(**attrs, &block)
72
+ @inertia_share ||= []
73
+ @inertia_share << attrs.freeze unless attrs.empty?
74
+ @inertia_share << block if block
75
+ end
76
+
77
+ def extract_inertia_share_options(props)
78
+ options = props.slice(:if, :unless, :only, :except)
79
+
80
+ return options if options.empty?
81
+
82
+ if props.except(:if, :unless, :only, :except).any?
83
+ raise ArgumentError, "You must not mix shared data and [:if, :unless, :only, :except] options, pass data as a hash or a block."
84
+ end
85
+
86
+ transform_inertia_share_option(options, :only, :if)
87
+ transform_inertia_share_option(options, :except, :unless)
88
+
89
+ options.transform_values! do |filters|
90
+ Array(filters).map!(&method(:filter_to_proc))
91
+ end
92
+
93
+ options
94
+ end
95
+
96
+ def transform_inertia_share_option(options, from, to)
97
+ if (from_value = options.delete(from))
98
+ filter = InertiaRails::ActionFilter.new(from, from_value)
99
+ options[to] = Array(options[to]).unshift(filter)
100
+ end
101
+ end
102
+
103
+ def filter_to_proc(filter)
104
+ case filter
105
+ when Symbol
106
+ -> { send(filter) }
107
+ when Proc
108
+ filter
109
+ when InertiaRails::ActionFilter
110
+ -> { filter.match?(self) }
111
+ else
112
+ raise ArgumentError, "You must pass a symbol or a proc as a filter."
113
+ end
114
+ end
58
115
  end
59
116
 
60
117
  def default_render
@@ -67,16 +124,7 @@ module InertiaRails
67
124
 
68
125
  def redirect_to(options = {}, response_options = {})
69
126
  capture_inertia_errors(response_options)
70
- super(options, response_options)
71
- end
72
-
73
- def redirect_back(fallback_location:, allow_other_host: true, **options)
74
- capture_inertia_errors(options)
75
- super(
76
- fallback_location: fallback_location,
77
- allow_other_host: allow_other_host,
78
- **options,
79
- )
127
+ super
80
128
  end
81
129
 
82
130
  private
@@ -109,7 +157,7 @@ module InertiaRails
109
157
 
110
158
  def capture_inertia_errors(options)
111
159
  if (inertia_errors = options.dig(:inertia, :errors))
112
- session[:inertia_errors] = inertia_errors
160
+ session[:inertia_errors] = inertia_errors.to_hash
113
161
  end
114
162
  end
115
163
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "3.3.0"
2
+ VERSION = "3.4.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
8
8
  - Brandon Shar
9
9
  - Eugene Granovsky
10
10
  autorequire:
11
- bindir: exe
11
+ bindir: bin
12
12
  cert_chain: []
13
- date: 2024-10-27 00:00:00.000000000 Z
13
+ date: 2024-11-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -18,113 +18,16 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5'
21
+ version: '6'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '5'
29
- - !ruby/object:Gem::Dependency
30
- name: bundler
31
- requirement: !ruby/object:Gem::Requirement
32
- requirements:
33
- - - "~>"
34
- - !ruby/object:Gem::Version
35
- version: '2.0'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '2.0'
43
- - !ruby/object:Gem::Dependency
44
- name: rake
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '13.0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '13.0'
57
- - !ruby/object:Gem::Dependency
58
- name: rspec-rails
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '4.0'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '4.0'
71
- - !ruby/object:Gem::Dependency
72
- name: rails-controller-testing
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
- - !ruby/object:Gem::Dependency
86
- name: sqlite3
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- - !ruby/object:Gem::Dependency
100
- name: responders
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: '0'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - ">="
111
- - !ruby/object:Gem::Version
112
- version: '0'
113
- - !ruby/object:Gem::Dependency
114
- name: debug
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
121
- prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- description:
28
+ version: '6'
29
+ description: Quickly build modern single-page React, Vue and Svelte apps using classic
30
+ server-side routing and controllers.
128
31
  email:
129
32
  - brian@bellawatt.com
130
33
  - brandon@bellawatt.com
@@ -133,20 +36,11 @@ executables: []
133
36
  extensions: []
134
37
  extra_rdoc_files: []
135
38
  files:
136
- - ".github/workflows/push.yml"
137
- - ".gitignore"
138
- - ".rspec"
139
39
  - CHANGELOG.md
140
- - CODE_OF_CONDUCT.md
141
- - Gemfile
142
40
  - LICENSE.txt
143
41
  - README.md
144
- - Rakefile
145
42
  - app/controllers/inertia_rails/static_controller.rb
146
43
  - app/views/inertia.html.erb
147
- - bin/console
148
- - bin/setup
149
- - inertia_rails.gemspec
150
44
  - lib/generators/inertia_rails/install/controller.rb
151
45
  - lib/generators/inertia_rails/install/react/InertiaExample.jsx
152
46
  - lib/generators/inertia_rails/install/react/inertia.jsx
@@ -156,6 +50,7 @@ files:
156
50
  - lib/generators/inertia_rails/install/vue/inertia.js
157
51
  - lib/generators/inertia_rails/install_generator.rb
158
52
  - lib/inertia_rails.rb
53
+ - lib/inertia_rails/action_filter.rb
159
54
  - lib/inertia_rails/configuration.rb
160
55
  - lib/inertia_rails/controller.rb
161
56
  - lib/inertia_rails/engine.rb
@@ -177,9 +72,12 @@ homepage: https://github.com/inertiajs/inertia-rails
177
72
  licenses:
178
73
  - MIT
179
74
  metadata:
75
+ bug_tracker_uri: https://github.com/inertiajs/inertia-rails/issues
76
+ changelog_uri: https://github.com/inertiajs/inertia-rails/blob/master/CHANGELOG.md
77
+ documentation_uri: https://github.com/inertiajs/inertia-rails/blob/master/README.md
180
78
  homepage_uri: https://github.com/inertiajs/inertia-rails
181
79
  source_code_uri: https://github.com/inertiajs/inertia-rails
182
- changelog_uri: https://github.com/inertiajs/inertia-rails/blob/master/CHANGELOG.md
80
+ rubygems_mfa_required: 'true'
183
81
  post_install_message:
184
82
  rdoc_options: []
185
83
  require_paths:
@@ -195,8 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
93
  - !ruby/object:Gem::Version
196
94
  version: '0'
197
95
  requirements: []
198
- rubygems_version: 3.5.10
96
+ rubygems_version: 3.5.11
199
97
  signing_key:
200
98
  specification_version: 4
201
- summary: Inertia adapter for Rails
99
+ summary: Inertia.js adapter for Rails
202
100
  test_files: []
@@ -1,33 +0,0 @@
1
- name: Testing
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- fail-fast: false
9
- matrix:
10
- ruby: ['3.1', '3.2', '3.3']
11
- rails: ['6.1', '7.0', '7.1']
12
-
13
- runs-on: ubuntu-latest
14
- name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
15
-
16
- steps:
17
- - uses: actions/checkout@v4
18
-
19
- - name: Setup System
20
- run: sudo apt-get install libsqlite3-dev
21
-
22
- - name: Set up Ruby
23
- uses: ruby/setup-ruby@v1
24
- with:
25
- ruby-version: ${{ matrix.ruby }}
26
- bundler-cache: true
27
- env:
28
- RAILS_VERSION: ${{ matrix.rails }}
29
-
30
- - name: Run tests
31
- run: bundle exec rake
32
- env:
33
- RAILS_VERSION: ${{ matrix.rails }}
data/.gitignore DELETED
@@ -1,25 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
- /Gemfile.lock
10
-
11
- /spec/dummy/db/*.sqlite3
12
- /spec/dummy/db/*.sqlite3-journal
13
- /spec/dummy/db/log/*.log
14
- /spec/dummy/tmp/
15
- /spec/dummy/.sass-cache
16
- /spec/dummy/log/
17
-
18
- # rspec failure tracking
19
- .rspec_status
20
-
21
- # Appraisal
22
- gemfiles/*.gemfile.lock
23
-
24
- # Local files, such as .env.development.local
25
- *.local
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require rails_helper
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at TODO: Write your email address. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in inertia-rails.gemspec
4
- gemspec
5
-
6
- version = ENV["RAILS_VERSION"] || "7.1"
7
- gem "rails", "~> #{version}.0"
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/bin/console DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "pathname"
4
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
5
- Pathname.new(__FILE__).realpath)
6
-
7
- require "rubygems"
8
- require "bundler/setup"
9
- require "rails/all"
10
- require "inertia_rails"
11
-
12
- require "irb"
13
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,37 +0,0 @@
1
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "inertia_rails/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "inertia_rails"
7
- spec.version = InertiaRails::VERSION
8
- spec.authors = ["Brian Knoles", "Brandon Shar", "Eugene Granovsky"]
9
- spec.email = ["brian@bellawatt.com", "brandon@bellawatt.com", "eugene@bellawatt.com"]
10
-
11
- spec.summary = %q{Inertia adapter for Rails}
12
- spec.homepage = "https://github.com/inertiajs/inertia-rails"
13
- spec.license = "MIT"
14
-
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = spec.homepage
17
- spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
18
-
19
- # Specify which files should be added to the gem when it is released.
20
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
- end
24
- spec.bindir = "exe"
25
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ["lib"]
27
-
28
- spec.add_runtime_dependency "railties", '>= 5'
29
-
30
- spec.add_development_dependency "bundler", "~> 2.0"
31
- spec.add_development_dependency "rake", "~> 13.0"
32
- spec.add_development_dependency "rspec-rails", "~> 4.0"
33
- spec.add_development_dependency "rails-controller-testing"
34
- spec.add_development_dependency "sqlite3"
35
- spec.add_development_dependency "responders"
36
- spec.add_development_dependency "debug"
37
- end