familia 1.0.0.pre.rc6 → 1.0.0.pre.rc7
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 +1 -1
- data/VERSION.yml +1 -1
- data/lib/familia/horreum/class_methods.rb +68 -20
- data/lib/familia/horreum.rb +3 -1
- data/lib/familia/redistype.rb +1 -1
- data/try/27_redis_horreum_try.rb +2 -2
- 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: 518b9d319e506964416166f2d84cc05d9d4a603de80b79a2f512fa9b751c4680
|
4
|
+
data.tar.gz: 9f1c9737d5d141050169da6123a977921e80768f056a0da138c299ccd7716abc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fed4bf1187d6d9ad477504343341c1f9a5bd59d0b7c276fbb8539086ddacfd2fa2306a55f9b2b10881cdd884ad38e6a9f392f79ed822fff270d97836d681260
|
7
|
+
data.tar.gz: 448a16b7b71afa58a27f0dfd464d85c495ddd517bf9eba5c622fab6c7b364566595e34d71934a2b9cd67b522e4b53ad94289a8097c8d819c011ad7e3e61bd6fe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/VERSION.yml
CHANGED
@@ -74,42 +74,90 @@ module Familia
|
|
74
74
|
fields << name
|
75
75
|
attr_accessor name
|
76
76
|
|
77
|
-
# Every field gets a fast
|
78
|
-
|
77
|
+
# Every field gets a fast attribute method for immediately persisting
|
78
|
+
fast_attribute! name
|
79
79
|
end
|
80
80
|
|
81
|
-
# Defines a fast
|
82
|
-
# attribute name. Fast
|
83
|
-
# attribute values to Redis. Calling a fast
|
84
|
-
# effect on any of the object's other attributes and does not
|
85
|
-
# a
|
81
|
+
# Defines a fast attribute method with a bang (!) suffix for a given
|
82
|
+
# attribute name. Fast attribute methods are used to immediately read or
|
83
|
+
# write attribute values from/to Redis. Calling a fast attribute method
|
84
|
+
# has no effect on any of the object's other attributes and does not
|
85
|
+
# trigger a call to update the object's expiration time.
|
86
86
|
#
|
87
87
|
# The dynamically defined method performs the following:
|
88
|
-
# -
|
88
|
+
# - Acts as both a reader and a writer method.
|
89
|
+
# - When called without arguments, retrieves the current value from Redis.
|
90
|
+
# - When called with an argument, persists the value to Redis immediately.
|
91
|
+
# - Checks if the correct number of arguments is provided (zero or one).
|
89
92
|
# - Converts the provided value to a format suitable for Redis storage.
|
90
|
-
# - Uses the existing accessor method to set the attribute value
|
91
|
-
#
|
92
|
-
# -
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
|
93
|
+
# - Uses the existing accessor method to set the attribute value when
|
94
|
+
# writing.
|
95
|
+
# - Persists the value to Redis immediately using the hset command when
|
96
|
+
# writing.
|
97
|
+
# - Includes custom error handling to raise an ArgumentError if the wrong
|
98
|
+
# number of arguments is given.
|
99
|
+
# - Raises a custom error message if an exception occurs during the
|
100
|
+
# execution of the method.
|
101
|
+
#
|
102
|
+
# @param [Symbol, String] name the name of the attribute for which the
|
103
|
+
# fast method is defined.
|
104
|
+
# @return [Object] the current value of the attribute when called without
|
105
|
+
# arguments.
|
106
|
+
# @raise [ArgumentError] if more than one argument is provided.
|
107
|
+
# @raise [RuntimeError] if an exception occurs during the execution of the
|
108
|
+
# method.
|
109
|
+
#
|
110
|
+
def fast_attribute!(name = nil)
|
111
|
+
# Fast attribute accessor method for the '#{name}' attribute.
|
112
|
+
# This method provides immediate read and write access to the attribute
|
113
|
+
# in Redis.
|
114
|
+
#
|
115
|
+
# When called without arguments, it retrieves the current value of the
|
116
|
+
# attribute from Redis.
|
117
|
+
# When called with an argument, it immediately persists the new value to
|
118
|
+
# Redis.
|
119
|
+
#
|
120
|
+
# @overload #{name}!
|
121
|
+
# Retrieves the current value of the attribute from Redis.
|
122
|
+
# @return [Object] the current value of the attribute.
|
123
|
+
#
|
124
|
+
# @overload #{name}!(value)
|
125
|
+
# Sets and immediately persists the new value of the attribute to
|
126
|
+
# Redis.
|
127
|
+
# @param value [Object] the new value to set for the attribute.
|
128
|
+
# @return [Object] the newly set value.
|
129
|
+
#
|
130
|
+
# @raise [ArgumentError] if more than one argument is provided.
|
131
|
+
# @raise [RuntimeError] if an exception occurs during the execution of
|
132
|
+
# the method.
|
133
|
+
#
|
134
|
+
# @note This method bypasses any object-level caching and interacts
|
135
|
+
# directly with Redis. It does not trigger updates to other attributes
|
136
|
+
# or the object's expiration time.
|
137
|
+
#
|
138
|
+
# @example
|
139
|
+
#
|
140
|
+
# def #{name}!(*args)
|
141
|
+
# # Method implementation
|
142
|
+
# end
|
143
|
+
#
|
100
144
|
define_method :"#{name}!" do |*args|
|
101
145
|
# Check if the correct number of arguments is provided (exactly one).
|
102
|
-
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1)" if args.size
|
146
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0 or 1)" if args.size > 1
|
103
147
|
|
104
148
|
val = args.first
|
105
149
|
|
150
|
+
# If no value is provided to this fast attribute method, make a call
|
151
|
+
# to redis to return the current stored value of the hash field.
|
152
|
+
return hget name if val.nil?
|
153
|
+
|
106
154
|
begin
|
107
155
|
# Trace the operation if debugging is enabled.
|
108
156
|
Familia.trace :FAST_WRITER, redis, "#{name}: #{val.inspect}", caller(1..1) if Familia.debug?
|
109
157
|
|
110
158
|
# Convert the provided value to a format suitable for Redis storage.
|
111
159
|
prepared = to_redis(val)
|
112
|
-
Familia.ld "[.
|
160
|
+
Familia.ld "[.fast_attribute!] #{name} val: #{val.class} prepared: #{prepared.class}"
|
113
161
|
|
114
162
|
# Use the existing accessor method to set the attribute value.
|
115
163
|
send :"#{name}=", val
|
data/lib/familia/horreum.rb
CHANGED
@@ -142,9 +142,11 @@ module Familia
|
|
142
142
|
#
|
143
143
|
opts[:parent] = self # unless opts.key(:parent)
|
144
144
|
|
145
|
+
suffix_override = opts.fetch(:suffix, name)
|
146
|
+
|
145
147
|
# Instantiate the RedisType object and below we store it in
|
146
148
|
# an instance variable.
|
147
|
-
redis_type = klass.new
|
149
|
+
redis_type = klass.new suffix_override, opts
|
148
150
|
|
149
151
|
# Freezes the redis_type, making it immutable.
|
150
152
|
# This ensures the object's state remains consistent and prevents any modifications,
|
data/lib/familia/redistype.rb
CHANGED
data/try/27_redis_horreum_try.rb
CHANGED
@@ -47,12 +47,12 @@ Familia.debug = false
|
|
47
47
|
@customer.save
|
48
48
|
#=> true
|
49
49
|
|
50
|
-
## Horreum object fields have a fast
|
50
|
+
## Horreum object fields have a fast attribute method (1 of 2)
|
51
51
|
Familia.trace :LOAD, @customer.redis, @customer.redisuri, caller if Familia.debug?
|
52
52
|
@customer.name! 'Jane Doe'
|
53
53
|
#=> 0
|
54
54
|
|
55
|
-
## Horreum object fields have a fast
|
55
|
+
## Horreum object fields have a fast attribute method (2 of 2)
|
56
56
|
@customer.refresh!
|
57
57
|
@customer.name
|
58
58
|
#=> "Jane Doe"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: familia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.rc7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|