thread_local_var_accessors 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +27 -6
- data/lib/thread_local_var_accessors/version.rb +1 -1
- 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: f567c363dc63194dc30aeae5d661ea14c871f9f64cc65ed3d2c2947447d1fc91
|
4
|
+
data.tar.gz: 30c3bc0763221a483de2370af6843c83b39ff6429f27f1b6ad796931fa9dae51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59329574532e6730a71d3f44d011bedae930ee29a0b592f9ff8fbf7ed6d824a13cb65ab9f51edb40df372615c5975f459bd483fc467f5914af48f992a21f7cfc
|
7
|
+
data.tar.gz: 822c3f467f172562efdab7a38cc73063b42b8937f09d71ad01345c52d80fa69bc438a60067756386aa8d4d8ba74055513cd4303875a3784b13a5d07e3120adcc
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -105,17 +105,30 @@ Then:
|
|
105
105
|
|
106
106
|
## Usage
|
107
107
|
|
108
|
-
|
108
|
+
To use the class methods, they must be included into the current module or class, with:
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
class MyNewClass
|
111
|
+
include ThreadLocalVarAccessors
|
112
|
+
...
|
113
|
+
end
|
114
|
+
|
115
|
+
With the include above, you can use the class methods to declare instance getter and setter methods:
|
116
|
+
|
117
|
+
class MyNewClass
|
118
|
+
include ThreadLocalVarAccessors
|
119
|
+
|
120
|
+
tlv_reader :name1
|
121
|
+
tlv_writer :name2
|
122
|
+
tlv_accessor :name3, :name4
|
123
|
+
|
124
|
+
end
|
113
125
|
|
114
126
|
The above invocations:
|
127
|
+
|
115
128
|
- create reader methods for `name1`, `name3`, and `name4`.
|
116
129
|
- create writer methods for `name2`, `name3`, and `name4`.
|
117
130
|
|
118
|
-
The writer methods accept a value as the second argument, or from the result of an associated block.
|
131
|
+
The writer methods accept a value as the second argument, or from the result of an optional, associated block.
|
119
132
|
|
120
133
|
Note: to use the read-and-operate operators, eg: `+=`, `-=`, `||=`, etc., the object must have both a reader and writer method. In other words, it needs to have been created as an `tlv_accessor`.
|
121
134
|
|
@@ -130,9 +143,17 @@ Alternative block forms:
|
|
130
143
|
tlv_set(name) { |oldval| newval }
|
131
144
|
tlv_set_once(name) { |oldval| newval }
|
132
145
|
|
133
|
-
|
134
146
|
In all cases, the `name` can be a string or symbol, with or without a leading `@`.
|
135
147
|
|
148
|
+
Ultimately, these methods are all doing these basic accesses of the corresponding instance variables:
|
149
|
+
|
150
|
+
@name1 ||= ThreadLocalVar.new
|
151
|
+
@name1.value = per_thread_value
|
152
|
+
...
|
153
|
+
@name1.value # returns the per_thread_value
|
154
|
+
|
155
|
+
If you prefer the style above, then you don't really need these accessor methods.
|
156
|
+
|
136
157
|
### Example Usage
|
137
158
|
|
138
159
|
```ruby
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thread_local_var_accessors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Stebbens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|