Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ PATH
remote: .
specs:
xdr (3.0.3)
activemodel (>= 4.2, < 8.0)
activesupport (>= 4.2, < 8.0)

GEM
remote: https://rubygems.org/
specs:
activemodel (7.0.2.2)
activesupport (= 7.0.2.2)
activesupport (7.0.2.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
Expand Down
1 change: 0 additions & 1 deletion lib/xdr.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "xdr/version"
require "active_model"
require "active_support/concern"
require "active_support/dependencies/autoload"
require "active_support/core_ext/object/blank"
Expand Down
2 changes: 0 additions & 2 deletions lib/xdr/dsl/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ def attribute(name, type)
define_method "#{name}=" do |v|
write_attribute(name, v)
end

define_attribute_methods name
end
end
1 change: 0 additions & 1 deletion lib/xdr/dsl/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def attribute(name, type)
raise ArgumentError, "#{type} does not convert to xdr" unless type.is_a?(XDR::Concerns::ConvertsToXDR)

self.arms = arms.merge(name => type)
define_attribute_methods name
end

private
Expand Down
13 changes: 4 additions & 9 deletions lib/xdr/struct.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
require "base64"

class XDR::Struct
include ActiveModel::Model
include ActiveModel::AttributeMethods

extend XDR::Concerns::ConvertsToXDR
extend XDR::DSL::Struct

attribute_method_prefix "read_"
attribute_method_suffix "write_"

class_attribute :fields
self.fields = ActiveSupport::OrderedHash.new

validates_with XDR::StructValidator

attr_reader :attributes

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

def initialize(attributes = {})
@attributes = {}
super

attributes.each do |name, value|
write_attribute(name, value)
end
end

#
Expand Down
6 changes: 0 additions & 6 deletions lib/xdr/struct_validator.rb

This file was deleted.

23 changes: 13 additions & 10 deletions lib/xdr/union.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class XDR::Union
include ActiveModel::Model
include ActiveModel::AttributeMethods

extend XDR::Concerns::ConvertsToXDR
extend XDR::DSL::Union

Expand All @@ -17,8 +14,6 @@ class XDR::Union
self.switch_type = nil
self.switch_name = nil

attribute_method_suffix "!"

def self.arm_for_switch(switch)
begin
switch = normalize_switch switch
Expand Down Expand Up @@ -100,16 +95,24 @@ def value

alias_method :get, :value

def attribute(attr)
return nil unless @arm.to_s == attr
def method_missing(method)
is_bang = method.end_with?("!")
attr = method.to_s.delete_suffix("!")

super unless self.class.arms.key?(attr.to_sym)

if @arm.to_s != attr
return nil unless is_bang
raise XDR::ArmNotSetError, "#{attr} is not the set arm"
end

get
end

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

get
self.class.arms.key?(attr.to_sym) || super
end

#
Expand Down
7 changes: 0 additions & 7 deletions lib/xdr/union_validator.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/lib/xdr/dsl/union_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
expect { klass.new(-1) }.to raise_error(XDR::InvalidSwitchError)
end

it "allows bool types", :focus do
it "allows bool types" do
klass = nil

expect do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }

RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
1 change: 0 additions & 1 deletion xdr.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 2.4.0"

spec.add_dependency "activesupport", ">= 4.2", "< 8.0"
spec.add_dependency "activemodel", ">= 4.2", "< 8.0"
end