Skip to content

Commit 063fd5d

Browse files
remove ostruct use
1 parent e735d96 commit 063fd5d

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
- Support for Ruby 3.4.
66

7+
## Fixed
8+
9+
- OStruct was listed as a development dependency instead of a runtime dependency.
10+
The need for OStruct has been removed entirely.
11+
712
# [5.4.0][] (2024-11-23)
813

914
## Added

active_interaction.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Gem::Specification.new do |spec|
4242
'actionpack' => [],
4343
'activerecord' => [],
4444
'kramdown' => ['~> 2.1'],
45-
'ostruct' => ['~> 0.6'],
4645
'rake' => ['~> 13.0'],
4746
'rspec' => ['~> 3.5'],
4847
'rubocop' => ['~> 1.68.0'],
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
11
# frozen_string_literal: true
22

3-
require 'ostruct'
4-
53
module ActiveInteraction
64
# Holds a group of inputs together for passing from {Base} to {Filter}s.
75
#
86
# @private
9-
class GroupedInput < OpenStruct
7+
class GroupedInput
8+
include Comparable
9+
10+
attr_reader :data
11+
protected :data
12+
13+
def initialize(**data)
14+
@data = data
15+
end
16+
17+
def [](key)
18+
@data[key]
19+
end
20+
21+
def []=(key, value)
22+
@data[key] = value
23+
end
24+
25+
def <=>(other)
26+
return nil unless other.is_a?(self.class)
27+
28+
data <=> other.data
29+
end
1030
end
1131
end
Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
RSpec.describe ActiveInteraction::GroupedInput do
2-
subject(:grouped_input) { described_class.new }
2+
describe '.new' do
3+
it 'adds all values to the object' do
4+
grouped_input = described_class.new('1' => 1, '2' => 2)
35

4-
it 'subclasses OpenStruct' do
5-
expect(grouped_input).to be_an OpenStruct
6+
expect(grouped_input['1']).to be 1
7+
expect(grouped_input['2']).to be 2
8+
end
69
end
710

8-
it 'responds to #[]' do
9-
expect { grouped_input[:key] }.to_not raise_error
11+
describe '#[]' do
12+
it 'returns nil if the key does not exist' do
13+
grouped_input = described_class.new
14+
15+
expect(grouped_input['1']).to be_nil
16+
end
17+
18+
it 'returns a value if the key exists' do
19+
grouped_input = described_class.new('1' => 1)
20+
21+
expect(grouped_input['1']).to be 1
22+
end
1023
end
1124

12-
it 'responds to #[]=' do
13-
expect { grouped_input[:key] = :value }.to_not raise_error
25+
describe '#[]=' do
26+
it 'sets the key does not exist' do
27+
grouped_input = described_class.new
28+
29+
expect(grouped_input['1'] = 1).to be 1
30+
expect(grouped_input['1']).to be 1
31+
end
1432
end
1533
end

0 commit comments

Comments
 (0)