cattri 0.2.0 → 0.2.1
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/CHANGELOG.md +22 -0
- data/README.md +4 -1
- data/bin/console +0 -25
- data/lib/cattri/initializer_patch.rb +2 -1
- data/lib/cattri/version.rb +1 -1
- data/sig/lib/cattri/attribute.rbs +11 -1
- data/sig/lib/cattri/attribute_registry.rbs +7 -1
- data/sig/lib/cattri/dsl.rbs +13 -2
- data/sig/lib/cattri/types.rbs +0 -10
- 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: 6570d6da579ae6a15c865884a895a1ef0923eafd610d2a97a474d4a888af5778
|
4
|
+
data.tar.gz: 6f01dcc2490c4c4ef159d5fcf88c87ab50204c293ce403e87440b87130add491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dbe7c5e9a7a8f4edcc160dc6952f42e80fd0ee5c602b65113fda8059663634c9c3d7d418044a7584626e8c9294240ad78be77a32b5dcabfa94d8498d2f76178
|
7
|
+
data.tar.gz: 301099ebc23bc730ada63468003fe1c9cd462e0040cbc8bc194d4a015d03a59c2b777482a4a142d5c215d93bc4083b7d2f5e33dec172e97ba343b5c48085f1a5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## [0.2.1] - 2025-05-01
|
2
|
+
|
3
|
+
- Fixed an issue where only `final: true` instance variables defined on the current/class had their values applied.
|
4
|
+
- Now walks the ancestor tree to ensure all attributes get set.
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
module Options
|
8
|
+
include Cattri
|
9
|
+
|
10
|
+
cattri :enabled, true, final: true # wasn't being set previously
|
11
|
+
end
|
12
|
+
|
13
|
+
class Attribute
|
14
|
+
include Options
|
15
|
+
|
16
|
+
def initialize(enabled: true)
|
17
|
+
seld.enabled = enabled
|
18
|
+
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
- Cleanup of `cattri.gemspec` and `bin/console`.
|
22
|
+
|
1
23
|
## [0.2.0] - 2025-05-01
|
2
24
|
|
3
25
|
### Changed
|
data/README.md
CHANGED
@@ -55,7 +55,10 @@ class User
|
|
55
55
|
cattri :id, -> { SecureRandom.uuid }, final: true
|
56
56
|
|
57
57
|
# Writable instance-level attributes
|
58
|
-
cattri :name, "anonymous"
|
58
|
+
cattri :name, "anonymous" do |value|
|
59
|
+
value.to_s.capitalize # custom setter/coercer
|
60
|
+
end
|
61
|
+
|
59
62
|
cattri :admin, false, predicate: true
|
60
63
|
|
61
64
|
def initialize(id)
|
data/bin/console
CHANGED
@@ -4,30 +4,5 @@
|
|
4
4
|
require "bundler/setup"
|
5
5
|
require "cattri"
|
6
6
|
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# class Tester
|
11
|
-
# include Cattri
|
12
|
-
#
|
13
|
-
# cattr :public_attr, default: 1
|
14
|
-
#
|
15
|
-
# protected
|
16
|
-
# cattr :protected_attr, default: 2
|
17
|
-
#
|
18
|
-
# private
|
19
|
-
# cattr :private_attr, default: 3
|
20
|
-
#
|
21
|
-
# class << self
|
22
|
-
# def protected_proxy
|
23
|
-
# self.protected_attr
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# def private_proxy
|
27
|
-
# self.private_attr
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
|
32
7
|
require "irb"
|
33
8
|
IRB.start(__FILE__)
|
@@ -26,7 +26,8 @@ module Cattri
|
|
26
26
|
def initialize(*args, **kwargs, &block)
|
27
27
|
super
|
28
28
|
|
29
|
-
self.class.send(:attribute_registry)
|
29
|
+
registry = self.class.send(:attribute_registry)
|
30
|
+
registry.defined_attributes(with_ancestors: true).each_value do |attribute| # steep:ignore
|
30
31
|
next if cattri_variable_defined?(attribute.ivar) # steep:ignore
|
31
32
|
next unless attribute.final?
|
32
33
|
|
data/lib/cattri/version.rb
CHANGED
@@ -27,7 +27,17 @@ module Cattri
|
|
27
27
|
# @param options [Hash] configuration options
|
28
28
|
# @option options [Boolean] :class whether the attribute is class-level (internally mapped to :class_attribute)
|
29
29
|
# @param transformer [Proc] optional block used to coerce/validate assigned values
|
30
|
-
def initialize: (
|
30
|
+
def initialize: (
|
31
|
+
identifier name,
|
32
|
+
defined_in: ::Module,
|
33
|
+
?ivar: identifier,
|
34
|
+
?final: bool,
|
35
|
+
?scope: scope_types,
|
36
|
+
?predicate: bool,
|
37
|
+
?default: ::Proc | untyped | nil,
|
38
|
+
?expose: expose_types,
|
39
|
+
?visibility: visibility_types
|
40
|
+
) { (?) -> untyped } -> void
|
31
41
|
|
32
42
|
# Serializes this attribute and its configuration to a frozen hash.
|
33
43
|
#
|
@@ -55,7 +55,13 @@ module Cattri
|
|
55
55
|
def define_attribute: (
|
56
56
|
identifier name,
|
57
57
|
Proc | untyped value,
|
58
|
-
|
58
|
+
?ivar: identifier,
|
59
|
+
?final: bool,
|
60
|
+
?scope: scope_types,
|
61
|
+
?predicate: bool,
|
62
|
+
?default: ::Proc | untyped | nil,
|
63
|
+
?expose: expose_types,
|
64
|
+
?visibility: visibility_types
|
59
65
|
) { (?) -> untyped } -> ::Array[::Symbol]
|
60
66
|
|
61
67
|
# Copies registered attributes from this context to another,
|
data/sig/lib/cattri/dsl.rbs
CHANGED
@@ -28,7 +28,13 @@ module Cattri
|
|
28
28
|
def cattri: (
|
29
29
|
identifier? name,
|
30
30
|
?untyped? value,
|
31
|
-
|
31
|
+
?ivar: identifier,
|
32
|
+
?final: bool,
|
33
|
+
?scope: scope_types,
|
34
|
+
?predicate: bool,
|
35
|
+
?default: ::Proc | untyped | nil,
|
36
|
+
?expose: expose_types,
|
37
|
+
?visibility: visibility_types
|
32
38
|
) { (?) -> untyped } -> ::Array[::Symbol]
|
33
39
|
|
34
40
|
# Defines a write-once (final) attribute.
|
@@ -49,7 +55,12 @@ module Cattri
|
|
49
55
|
def final_cattri: (
|
50
56
|
identifier name,
|
51
57
|
untyped value,
|
52
|
-
|
58
|
+
?ivar: identifier,
|
59
|
+
?scope: scope_types,
|
60
|
+
?predicate: bool,
|
61
|
+
?default: ::Proc | untyped | nil,
|
62
|
+
?expose: expose_types,
|
63
|
+
?visibility: visibility_types
|
53
64
|
) { (?) -> untyped } -> ::Array[::Symbol]
|
54
65
|
end
|
55
66
|
end
|
data/sig/lib/cattri/types.rbs
CHANGED
@@ -6,14 +6,4 @@ module Cattri
|
|
6
6
|
type expose_types = :read_write | :read | :write | :none
|
7
7
|
|
8
8
|
type visibility_types = :public | :protected | :private
|
9
|
-
|
10
|
-
type attribute_options = {
|
11
|
-
ivar?: identifier,
|
12
|
-
final: bool,
|
13
|
-
scope?: scope_types,
|
14
|
-
predicate?: bool,
|
15
|
-
default?: ::Proc | untyped,
|
16
|
-
expose?: expose_types,
|
17
|
-
visibility?: visibility_types
|
18
|
-
}
|
19
9
|
end
|
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.1
|
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-05-
|
11
|
+
date: 2025-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debride
|