Skip to content

Commit 3d554c3

Browse files
committed
chore: remove ActiveModel dependency
1 parent a807558 commit 3d554c3

File tree

10 files changed

+21
-39
lines changed

10 files changed

+21
-39
lines changed

Gemfile.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ PATH
22
remote: .
33
specs:
44
xdr (3.0.3)
5-
activemodel (>= 4.2, < 8.0)
65
activesupport (>= 4.2, < 8.0)
76

87
GEM
98
remote: https://rubygems.org/
109
specs:
11-
activemodel (7.0.2.2)
12-
activesupport (= 7.0.2.2)
1310
activesupport (7.0.2.2)
1411
concurrent-ruby (~> 1.0, >= 1.0.2)
1512
i18n (>= 1.6, < 2)

lib/xdr/dsl/struct.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def attribute(name, type)
1414
write_attribute(name, v)
1515
end
1616

17-
define_attribute_methods name
17+
# define_attribute_methods name
1818
end
1919
end

lib/xdr/dsl/union.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def attribute(name, type)
1818
raise ArgumentError, "#{type} does not convert to xdr" unless type.is_a?(XDR::Concerns::ConvertsToXDR)
1919

2020
self.arms = arms.merge(name => type)
21-
define_attribute_methods name
2221
end
2322

2423
private

lib/xdr/struct.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
require "base64"
22

33
class XDR::Struct
4-
include ActiveModel::Model
5-
include ActiveModel::AttributeMethods
6-
74
extend XDR::Concerns::ConvertsToXDR
85
extend XDR::DSL::Struct
96

10-
attribute_method_prefix "read_"
11-
attribute_method_suffix "write_"
12-
137
class_attribute :fields
148
self.fields = ActiveSupport::OrderedHash.new
159

16-
validates_with XDR::StructValidator
17-
1810
attr_reader :attributes
1911

2012
def self.read(io)
@@ -38,7 +30,10 @@ def self.valid?(val)
3830

3931
def initialize(attributes = {})
4032
@attributes = {}
41-
super
33+
34+
attributes.each do |name, value|
35+
write_attribute(name, value)
36+
end
4237
end
4338

4439
#

lib/xdr/struct_validator.rb

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/xdr/union.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
class XDR::Union
2-
include ActiveModel::Model
3-
include ActiveModel::AttributeMethods
4-
52
extend XDR::Concerns::ConvertsToXDR
63
extend XDR::DSL::Union
74

@@ -17,8 +14,6 @@ class XDR::Union
1714
self.switch_type = nil
1815
self.switch_name = nil
1916

20-
attribute_method_suffix "!"
21-
2217
def self.arm_for_switch(switch)
2318
begin
2419
switch = normalize_switch switch
@@ -100,16 +95,24 @@ def value
10095

10196
alias_method :get, :value
10297

103-
def attribute(attr)
104-
return nil unless @arm.to_s == attr
98+
def method_missing(method)
99+
is_bang = method.end_with?("!")
100+
attr = method.to_s.delete_suffix("!")
101+
102+
super unless self.class.arms.key?(attr.to_sym)
103+
104+
if @arm.to_s != attr
105+
return nil unless is_bang
106+
raise XDR::ArmNotSetError, "#{attr} is not the set arm"
107+
end
105108

106109
get
107110
end
108111

109-
def attribute!(attr)
110-
raise XDR::ArmNotSetError, "#{attr} is not the set arm" unless @arm.to_s == attr
112+
def respond_to_missing?(method, *)
113+
attr = method.to_s.delete_suffix("!")
111114

112-
get
115+
self.class.arms.key?(attr.to_sym) || super
113116
end
114117

115118
#

lib/xdr/union_validator.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

spec/lib/xdr/dsl/union_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
expect { klass.new(-1) }.to raise_error(XDR::InvalidSwitchError)
5252
end
5353

54-
it "allows bool types", :focus do
54+
it "allows bool types" do
5555
klass = nil
5656

5757
expect do

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
66

77
RSpec.configure do |config|
8+
config.filter_run focus: true
9+
config.run_all_when_everything_filtered = true
810
end

xdr.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ Gem::Specification.new do |spec|
2424
spec.required_ruby_version = ">= 2.4.0"
2525

2626
spec.add_dependency "activesupport", ">= 4.2", "< 8.0"
27-
spec.add_dependency "activemodel", ">= 4.2", "< 8.0"
2827
end

0 commit comments

Comments
 (0)