alba-inertia 0.1.3 → 0.1.4

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: f8c5c1926cf157ea4d3cfc5b1c93a0a4899186c034926871ee506f109677a5d7
4
- data.tar.gz: 1fee181488d0ca6d5852d2c8fe1f7b57df023e85648a98ba9b42e46d023ee71b
3
+ metadata.gz: cfe281c753944eadf0114123a314af226fb73fadeac1053a89c11c87577cdc6c
4
+ data.tar.gz: ad63713f57f9066ec4f0de804d51cd6ea856eec0d09e3e17a443f5327b0a128c
5
5
  SHA512:
6
- metadata.gz: 4a705b90d9050542fbfc152a915ad808685dbeb450bba8001672be0545f4c1b1986c08c9e97098d9454556ceb000f09cc92bdb848b3bb3d6ecf8f4fa7c98cf99
7
- data.tar.gz: '098535869f8f87c9ef4eb4655589ee6813324ec925b8c4bd5387fe8349e453ca05b486f6bad1ecb97440ab3e943322e0dce33ee61d24d8119e25cd4021929381'
6
+ metadata.gz: 207186eb671f60205cd46f03862d84e6569473b18a7424f19c1eaae61435408fd5aeaf167e7642e9f0d46d3749af6f4ebef92e5d08ca394029e069f3de4f3e98
7
+ data.tar.gz: 6f6b0825a3bfbe83b1d4cd6c42ae2b2e2d9d789d5c84dfd79d36b480b1d9b9c879feed73b531a40789022f1439e163e6fc62ffdec34c1c1285a6675229b091fb
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning].
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.4] - 2026-04-21
11
+
12
+ ### Added
13
+
14
+ - Support for `InertiaRails.cache` props. ([@skryukov])
15
+ - Support for deferred scroll props. ([@nickpellant])
16
+ - Respect configured `transform_keys` on top-level prop keys. ([@bknoles])
17
+
18
+ ### Changed
19
+
20
+ - Compatibility with InertiaRails 3.19.0+ load path. ([@bknoles])
21
+
10
22
  ## [0.1.3] - 2025-12-08
11
23
 
12
24
  ### Added
@@ -37,9 +49,12 @@ and this project adheres to [Semantic Versioning].
37
49
 
38
50
  - Initial release ([@skryukov])
39
51
 
52
+ [@bknoles]: https://github.com/bknoles
53
+ [@nickpellant]: https://github.com/nickpellant
40
54
  [@skryukov]: https://github.com/skryukov
41
55
 
42
- [Unreleased]: https://github.com/skryukov/alba-inertia/compare/v0.1.3...HEAD
56
+ [Unreleased]: https://github.com/skryukov/alba-inertia/compare/v0.1.4...HEAD
57
+ [0.1.4]: https://github.com/skryukov/alba-inertia/compare/v0.1.3...v0.1.4
43
58
  [0.1.3]: https://github.com/skryukov/alba-inertia/compare/v0.1.2...v0.1.3
44
59
  [0.1.2]: https://github.com/skryukov/alba-inertia/compare/v0.1.1...v0.1.2
45
60
  [0.1.1]: https://github.com/skryukov/alba-inertia/compare/v0.1.0...v0.1.1
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Alba::Inertia
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/alba-inertia.svg)](https://rubygems.org/gems/alba-inertia)
4
+
3
5
  Seamless integration between [Alba](https://github.com/okuramasafumi/alba) serializers and [Inertia Rails](https://inertia-rails.dev/).
4
6
 
5
7
  ## Features
@@ -8,6 +10,10 @@ Seamless integration between [Alba](https://github.com/okuramasafumi/alba) seria
8
10
  - Lazy evaluation for efficient data loading on partial reloads
9
11
  - Auto-detection of resource classes based on controller/action naming
10
12
 
13
+ <a href="https://evilmartians.com/?utm_source=alba-inertia&utm_campaign=project_page">
14
+ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Built by Evil Martians" width="236" height="54">
15
+ </a>
16
+
11
17
  ## Installation
12
18
 
13
19
  Add to your Gemfile:
@@ -11,14 +11,16 @@ module Alba
11
11
  wrap_optional(evaluation_block, options[:optional], object)
12
12
  elsif options[:once]
13
13
  wrap_once(evaluation_block, options[:once], object)
14
+ elsif options[:scroll]
15
+ wrap_scroll(evaluation_block, options[:scroll], object, options)
14
16
  elsif options[:defer]
15
17
  wrap_defer(evaluation_block, options[:defer], object)
16
18
  elsif options[:merge]
17
19
  wrap_merge(evaluation_block, options[:merge], object)
18
- elsif options[:scroll]
19
- wrap_scroll(evaluation_block, options[:scroll], object)
20
20
  elsif options[:always]
21
21
  wrap_always(evaluation_block, options[:always], object)
22
+ elsif options[:cache]
23
+ wrap_cache(evaluation_block, options[:cache], object)
22
24
  else
23
25
  Alba::Inertia.config.lazy_by_default ? evaluation_block : evaluation_block.call
24
26
  end
@@ -30,9 +32,18 @@ module Alba
30
32
  ::InertiaRails.always(&value_block)
31
33
  end
32
34
 
35
+ def wrap_cache(value_block, opts, _object)
36
+ if opts.is_a?(Hash)
37
+ raise ArgumentError, "cache: hash requires a :key" unless opts.key?(:key)
38
+ ::InertiaRails.cache(opts[:key], **opts.except(:key), &value_block)
39
+ else
40
+ ::InertiaRails.cache(opts, &value_block)
41
+ end
42
+ end
43
+
33
44
  def wrap_optional(value_block, opts, _object)
34
45
  if opts.is_a?(Hash)
35
- options = opts.slice(*ONCE_KEYS)
46
+ options = opts.slice(:cache, *ONCE_KEYS)
36
47
  ::InertiaRails.optional(**options, &value_block)
37
48
  else
38
49
  ::InertiaRails.optional(&value_block)
@@ -50,7 +61,7 @@ module Alba
50
61
 
51
62
  def wrap_defer(value_block, opts, _object)
52
63
  if opts.is_a?(Hash)
53
- options = opts.slice(:group, :deep_merge, :merge, :match_on, *ONCE_KEYS)
64
+ options = opts.slice(:group, :deep_merge, :merge, :match_on, :cache, *ONCE_KEYS)
54
65
 
55
66
  ::InertiaRails.defer(**options, &value_block)
56
67
  else
@@ -67,23 +78,25 @@ module Alba
67
78
  end
68
79
  end
69
80
 
70
- def wrap_scroll(value_block, opts, object)
81
+ def wrap_scroll(value_block, opts, object, all_options = {})
82
+ extra = all_options.slice(:defer, :group)
83
+
71
84
  case opts
72
85
  when Symbol
73
86
  # scroll: :meta => extract metadata from object[:meta] or object.meta
74
87
  metadata = extract_from_object(object, opts)
75
- ::InertiaRails.scroll(metadata: metadata, &value_block)
88
+ ::InertiaRails.scroll(metadata: metadata, **extra, &value_block)
76
89
  when Proc
77
90
  # scroll: -> { |obj| obj.meta } => call proc with object
78
91
  metadata = opts.call(object)
79
- ::InertiaRails.scroll(metadata: metadata, &value_block)
92
+ ::InertiaRails.scroll(metadata: metadata, **extra, &value_block)
80
93
  when Hash
81
94
  options = build_scroll_options(opts, object)
82
95
  ::InertiaRails.scroll(**options, &value_block)
83
96
  when TrueClass
84
97
  # scroll: true => auto-detect metadata
85
98
  metadata = auto_detect_pagination_metadata(object)
86
- ::InertiaRails.scroll(metadata: metadata, &value_block)
99
+ ::InertiaRails.scroll(metadata: metadata, **extra, &value_block)
87
100
  else
88
101
  raise ArgumentError, "Invalid scroll option. Expected Symbol, Proc, Hash, or true."
89
102
  end
@@ -99,7 +112,7 @@ module Alba
99
112
  opts[:scroll]
100
113
  end
101
114
 
102
- {metadata: metadata}.merge(opts.slice(:wrapper, :page_name, :previous_page, :next_page, :current_page))
115
+ {metadata: metadata}.merge(opts.slice(:defer, :group, :wrapper, :page_name, :previous_page, :next_page, :current_page))
103
116
  end
104
117
 
105
118
  def extract_from_object(object, key)
@@ -56,16 +56,7 @@ module Alba
56
56
  #
57
57
  # @example Merge with custom options
58
58
  # inertia_prop :metadata, merge: { match_on: :id, prepend: 'meta_' }
59
- def inertia_prop(name, **kwargs)
60
- options = {
61
- optional: kwargs.delete(:optional) || false,
62
- once: kwargs.delete(:once) || false,
63
- defer: kwargs.delete(:defer) || false,
64
- merge: kwargs.delete(:merge) || false,
65
- scroll: kwargs.delete(:scroll) || false,
66
- always: kwargs.delete(:always) || false
67
- }.select { |_k, v| v.present? }
68
-
59
+ def inertia_prop(name, **options)
69
60
  inertia_metadata[name] = options.freeze
70
61
  auto_typelize_from_inertia(name, options)
71
62
  end
@@ -122,7 +113,7 @@ module Alba
122
113
  result = {}
123
114
 
124
115
  self.class._attributes.each do |attr_name, attr_body|
125
- attr_name_str = attr_name.to_s
116
+ attr_name_str = transform_key(attr_name)
126
117
 
127
118
  evaluation_block = build_evaluation_block(attr_name, attr_body)
128
119
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Alba
4
4
  module Inertia
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alba-inertia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  - !ruby/object:Gem::Version
92
92
  version: '0'
93
93
  requirements: []
94
- rubygems_version: 3.6.9
94
+ rubygems_version: 4.0.6
95
95
  specification_version: 4
96
96
  summary: Seamless integration between Alba and Inertia Rails.
97
97
  test_files: []