Skip to content

Commit 0a16df4

Browse files
princejosephclaude
andcommitted
Fix additional Rails 7 / Ruby 3 incompatibilities in hyper-model and hyper-operation
- Add **kwargs to has_many/belongs_to/composed_of wrapper methods in active_record_base.rb and permissions.rb so options are forwarded as keyword args (not positional hashes), fixing 'undefined method arity for Hash' errors in Rails 7.2 - Guard InternalMetadata.do_not_synchronize with respond_to? check since Rails 7.1+ no longer makes InternalMetadata inherit from ActiveRecord::Base - Add coder: YAML to serialize :data in QueuedMessage (required since Rails 7.1) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4d7cc65 commit 0a16df4

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

ruby/hyper-model/lib/active_record_base.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,16 @@ def has_many(name, *args, &block)
281281
method_defined?(:"__secure_remote_access_to_#{name}"),
282282
&method(:regulate_relationship)
283283
)
284-
pre_syncromesh_has_many name, *args, opts.except(:regulate), &block
284+
pre_syncromesh_has_many name, *args, **opts.except(:regulate), &block
285285
end
286286

287287
%i[belongs_to has_one composed_of].each do |macro|
288288
alias_method :"pre_syncromesh_#{macro}", macro
289-
define_method(macro) do |name, *aargs, &block|
289+
define_method(macro) do |name, *aargs, **kwargs, &block|
290290
define_method(:"__secure_remote_access_to_#{name}") do |this, _acting_user, *args|
291291
this.send(name, *args)
292292
end
293-
send(:"pre_syncromesh_#{macro}", name, *aargs, &block)
293+
send(:"pre_syncromesh_#{macro}", name, *aargs, **kwargs, &block)
294294
end
295295
end
296296
end
@@ -399,5 +399,6 @@ def __hyperstack_secure_attributes(acting_user)
399399
end
400400
end
401401

402-
InternalMetadata.do_not_synchronize if defined? InternalMetadata
402+
# Rails 7.1+ changed InternalMetadata to no longer inherit from ActiveRecord::Base
403+
InternalMetadata.do_not_synchronize if defined?(InternalMetadata) && InternalMetadata.respond_to?(:do_not_synchronize)
403404
end

ruby/hyper-model/lib/reactive_record/permissions.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ class << self
7474
attr_reader :reactive_record_association_keys
7575

7676
[:has_many, :belongs_to, :composed_of].each do |macro|
77-
define_method "#{macro}_with_reactive_record_add_changed_method".to_sym do |attr_name, *args, &block|
77+
define_method "#{macro}_with_reactive_record_add_changed_method".to_sym do |attr_name, *args, **kwargs, &block|
7878
define_method "#{attr_name}_changed?".to_sym do
7979
instance_variable_get "@reactive_record_#{attr_name}_changed".to_sym
8080
end
8181
(@reactive_record_association_keys ||= []) << attr_name
82-
send "#{macro}_without_reactive_record_add_changed_method".to_sym, attr_name, *args, &block
82+
send "#{macro}_without_reactive_record_add_changed_method".to_sym, attr_name, *args, **kwargs, &block
8383
end
8484
alias_method "#{macro}_without_reactive_record_add_changed_method".to_sym, macro
8585
alias_method macro, "#{macro}_with_reactive_record_add_changed_method".to_sym
8686
end
8787

8888
alias belongs_to_without_reactive_record_add_is_method belongs_to
8989

90-
def belongs_to(attr_name, *args)
91-
belongs_to_without_reactive_record_add_is_method(attr_name, *args).tap do
90+
def belongs_to(attr_name, *args, **kwargs)
91+
belongs_to_without_reactive_record_add_is_method(attr_name, *args, **kwargs).tap do
9292
define_method "#{attr_name}_is?".to_sym do |model|
9393
attributes[self.class.reflections[attr_name.to_s].foreign_key] == model.id
9494
end

ruby/hyper-operation/lib/hyper-operation/transport/connection_adapter/active_record/queued_message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QueuedMessage < ::ActiveRecord::Base
1212

1313
do_not_synchronize
1414

15-
serialize :data
15+
serialize :data, coder: YAML
1616

1717
belongs_to :hyperstack_connection,
1818
class_name: 'Hyperstack::ConnectionAdapter::ActiveRecord::Connection',

0 commit comments

Comments
 (0)