cattri 0.2.3 → 0.2.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: ba04c1c408b5ffe93591ba80633bc3b7d7950d0e651e4adf738e30fe4ba795ea
4
- data.tar.gz: a4d5f788238eee82419df14b8977b018ed8b7d91169f7719171186c26e9dde7d
3
+ metadata.gz: a81d60325f6f78ae5c66943a89b7dd77f6577a0d0aa4626edf28c0fbdf83cd0c
4
+ data.tar.gz: b3b458634e08b6c58ed3204de7c1b261082b50655e9430d7509e6cf4206b2f45
5
5
  SHA512:
6
- metadata.gz: 1a923822a64d948f87bc16c14511ab2b9a6d278f3b3a9264ee4ab57515644f3f42dedaee7db4bd3b6d5a7d294daf866a00dd99b0d4d72b29faade58f6facc0e2
7
- data.tar.gz: 26cc1589b802f4916b55b43312d567e7e68138a83e16780c6c5a49405b16e45a6325bfd5d5e39b7b80bbe5bdf53bbadd84b606765c156cf53183be6a49e251f9
6
+ metadata.gz: 6563f60e3f86a0509a03367be7c40a4d2f9820fd6e44bfd77f1111b89426ac526c33653c040cd51027a82e49c9dc5a77b6f7d1f56347bad9623b98d8d702f3b7
7
+ data.tar.gz: 11b6c7d02e22a206c70661d7d8ee93d03ba9a129b502911ed30c316c1477b1b065ef897e465dd3ab57532d21debf4c9fef15b835a12b48dc6edcc401db9046be
@@ -16,6 +16,9 @@ jobs:
16
16
  ruby:
17
17
  - '2.7.0'
18
18
  - '3.1.4'
19
+ - '3.2.9'
20
+ - '3.3.10'
21
+ - '3.4.7'
19
22
 
20
23
  steps:
21
24
  - uses: actions/checkout@v4
@@ -94,11 +94,11 @@ module Cattri
94
94
  %i[read read_write].include?(@options.expose)
95
95
  end
96
96
 
97
- # @return [Boolean] whether the attribute allows writing
97
+ # @return [Boolean] whether the attribute should define a writer (public or internal)
98
98
  def writable?
99
99
  return false if @options.expose == :none
100
100
 
101
- !readonly?
101
+ !readonly? || internal_writer?
102
102
  end
103
103
 
104
104
  # @return [Boolean] whether the attribute is marked readonly
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cattri
4
4
  # :nocov:
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.4"
6
6
  # :nocov:
7
7
  end
@@ -35,7 +35,7 @@ module Cattri
35
35
  ?default: ::Proc | untyped | nil,
36
36
  ?expose: expose_types,
37
37
  ?visibility: visibility_types
38
- ) { (?) -> untyped } -> ::Array[::Symbol]
38
+ ) ?{ (?) -> untyped } -> ::Array[::Symbol]
39
39
 
40
40
  # Defines a write-once (final) attribute.
41
41
  #
@@ -61,6 +61,6 @@ module Cattri
61
61
  ?default: ::Proc | untyped | nil,
62
62
  ?expose: expose_types,
63
63
  ?visibility: visibility_types
64
- ) { (?) -> untyped } -> ::Array[::Symbol]
64
+ ) ?{ (?) -> untyped } -> ::Array[::Symbol]
65
65
  end
66
66
  end
@@ -78,13 +78,37 @@ RSpec.describe Cattri::AttributeCompiler do
78
78
  )
79
79
  end
80
80
 
81
- it "does not define a writer" do
81
+ it "keeps the writer private" do
82
82
  described_class.define_accessor(attribute, context)
83
83
  instance = dummy_class.new
84
84
 
85
85
  expect(instance.visible).to eq("shown")
86
86
  expect(instance.respond_to?(:visible=)).to be(false)
87
- expect(instance.respond_to?(:visible=, true)).to be(false)
87
+ expect(instance.respond_to?(:visible=, true)).to be(true)
88
+
89
+ instance.send(:visible=, "hidden")
90
+ expect(instance.visible).to eq("hidden")
91
+ end
92
+ end
93
+
94
+ context "when writable? returns false" do
95
+ let(:attribute) do
96
+ Cattri::Attribute.new(
97
+ :disabled_writer,
98
+ defined_in: dummy_class,
99
+ default: -> { "initial" },
100
+ expose: :read_write
101
+ )
102
+ end
103
+
104
+ it "skips writer definition" do
105
+ allow(attribute).to receive(:writable?).and_return(false)
106
+
107
+ described_class.define_accessor(attribute, context)
108
+ instance = dummy_class.new
109
+
110
+ expect(instance).not_to respond_to(:disabled_writer=)
111
+ expect(instance.disabled_writer).to eq("initial")
88
112
  end
89
113
  end
90
114
  end
@@ -111,11 +111,11 @@ RSpec.describe Cattri::Attribute do
111
111
 
112
112
  describe "#writable?" do
113
113
  [
114
- [true, :read, false],
114
+ [true, :read, true],
115
115
  [true, :write, true],
116
116
  [true, :read_write, true],
117
117
  [true, :none, false],
118
- [false, :read, false],
118
+ [false, :read, true],
119
119
  [false, :write, true],
120
120
  [false, :read_write, true],
121
121
  [false, :none, false]
@@ -190,20 +190,26 @@ RSpec.describe Cattri::Attribute do
190
190
  end
191
191
 
192
192
  describe "#allowed_methods" do
193
- shared_examples_for "allowed method set" do |writable, predicate, expected|
194
- let(:expose) { writable ? :read_write : :read }
195
- let(:predicate) { predicate }
196
- let(:final) { false }
197
-
198
- it "returns #{expected.inspect} for writable: #{writable}, predicate: #{predicate}" do
199
- expect(attribute.allowed_methods).to eq(expected)
193
+ [
194
+ [:read_write, true, %i[attr attr= attr?]],
195
+ [:read_write, false, %i[attr attr=]],
196
+ [:read, true, %i[attr attr= attr?]],
197
+ [:read, false, %i[attr attr=]],
198
+ [:write, true, %i[attr attr= attr?]],
199
+ [:write, false, %i[attr attr=]],
200
+ [:none, true, %i[attr attr?]],
201
+ [:none, false, [:attr]]
202
+ ].each do |(exposure, predicate_value, expected)|
203
+ context "when expose is #{exposure} and predicate: #{predicate_value}" do
204
+ let(:expose) { exposure }
205
+ let(:predicate) { predicate_value }
206
+ let(:final) { false }
207
+
208
+ it "returns #{expected.inspect}" do
209
+ expect(attribute.allowed_methods).to eq(expected)
210
+ end
200
211
  end
201
212
  end
202
-
203
- it_behaves_like "allowed method set", true, true, %i[attr attr= attr?]
204
- it_behaves_like "allowed method set", true, false, %i[attr attr=]
205
- it_behaves_like "allowed method set", false, true, %i[attr attr?]
206
- it_behaves_like "allowed method set", false, false, [:attr]
207
213
  end
208
214
 
209
215
  describe "#validate_assignment!" do
data/spec/cattri_spec.rb CHANGED
@@ -206,6 +206,23 @@ RSpec.describe Cattri do
206
206
  expect(obj.token).to eq("abc123")
207
207
  expect { obj.token = "fail" }.to raise_error(Cattri::AttributeError)
208
208
  end
209
+
210
+ it "allows internal assignment for read-exposed attributes" do
211
+ klass = Class.new do
212
+ include Cattri
213
+
214
+ cattri :token, expose: :read
215
+
216
+ def initialize(token)
217
+ send(:token=, token)
218
+ end
219
+ end
220
+
221
+ instance = klass.new("abc123")
222
+
223
+ expect(instance.token).to eq("abc123")
224
+ expect { instance.token = "fail" }.to raise_error(NoMethodError)
225
+ end
209
226
  end
210
227
 
211
228
  describe "visibility with write-only exposure" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cattri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Lucas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-14 00:00:00.000000000 Z
11
+ date: 2025-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debride