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 +4 -4
- data/.github/workflows/main.yml +3 -0
- data/lib/cattri/attribute.rb +2 -2
- data/lib/cattri/version.rb +1 -1
- data/sig/lib/cattri/dsl.rbs +2 -2
- data/spec/cattri/attribute_compiler_spec.rb +26 -2
- data/spec/cattri/attribute_spec.rb +20 -14
- data/spec/cattri_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a81d60325f6f78ae5c66943a89b7dd77f6577a0d0aa4626edf28c0fbdf83cd0c
|
|
4
|
+
data.tar.gz: b3b458634e08b6c58ed3204de7c1b261082b50655e9430d7509e6cf4206b2f45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6563f60e3f86a0509a03367be7c40a4d2f9820fd6e44bfd77f1111b89426ac526c33653c040cd51027a82e49c9dc5a77b6f7d1f56347bad9623b98d8d702f3b7
|
|
7
|
+
data.tar.gz: 11b6c7d02e22a206c70661d7d8ee93d03ba9a129b502911ed30c316c1477b1b065ef897e465dd3ab57532d21debf4c9fef15b835a12b48dc6edcc401db9046be
|
data/.github/workflows/main.yml
CHANGED
data/lib/cattri/attribute.rb
CHANGED
|
@@ -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
|
|
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
|
data/lib/cattri/version.rb
CHANGED
data/sig/lib/cattri/dsl.rbs
CHANGED
|
@@ -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 "
|
|
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(
|
|
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,
|
|
114
|
+
[true, :read, true],
|
|
115
115
|
[true, :write, true],
|
|
116
116
|
[true, :read_write, true],
|
|
117
117
|
[true, :none, false],
|
|
118
|
-
[false, :read,
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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.
|
|
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-
|
|
11
|
+
date: 2025-12-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: debride
|