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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d368f329560a1afd7252a2c8de830a7230334933cd00715b4b952e44d9fbf63
4
- data.tar.gz: edd7b843ff07cf87aa2fe46766d7b0fd6dfa814b5404c9ca04bc42de18b05619
3
+ metadata.gz: 518b9d319e506964416166f2d84cc05d9d4a603de80b79a2f512fa9b751c4680
4
+ data.tar.gz: 9f1c9737d5d141050169da6123a977921e80768f056a0da138c299ccd7716abc
5
5
  SHA512:
6
- metadata.gz: 0f4db87dbaa2c12636d8293a477ef1e2a000364d3e6e2515cac90dad7277efc29d3670103cdf4f7697960ec90012ddec7071004146785ec7d3c838863e1a241b
7
- data.tar.gz: a1812fce749dc485753a10c39281feb1babab24fd95ecdd553398c4a07a800836d7bf4ac4a7574ee987d4d181842e089cd732efa343141a0bf4610594ea8f1cd
6
+ metadata.gz: 0fed4bf1187d6d9ad477504343341c1f9a5bd59d0b7c276fbb8539086ddacfd2fa2306a55f9b2b10881cdd884ad38e6a9f392f79ed822fff270d97836d681260
7
+ data.tar.gz: 448a16b7b71afa58a27f0dfd464d85c495ddd517bf9eba5c622fab6c7b364566595e34d71934a2b9cd67b522e4b53ad94289a8097c8d819c011ad7e3e61bd6fe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- familia (1.0.0.pre.rc6)
4
+ familia (1.0.0.pre.rc7)
5
5
  redis (>= 4.8.1, < 6.0)
6
6
  uri-redis (~> 1.3)
7
7
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Familia - 1.0.0-rc6 (August 2024)
1
+ # Familia - 1.0.0-rc7 (August 2024)
2
2
 
3
3
  **Organize and store Ruby objects in Redis. A powerful Ruby ORM (of sorts) for Redis.**
4
4
 
data/VERSION.yml CHANGED
@@ -2,4 +2,4 @@
2
2
  :MAJOR: 1
3
3
  :MINOR: 0
4
4
  :PATCH: 0
5
- :PRE: rc6
5
+ :PRE: rc7
@@ -74,42 +74,90 @@ module Familia
74
74
  fields << name
75
75
  attr_accessor name
76
76
 
77
- # Every field gets a fast writer method for immediately persisting
78
- fast_writer! name
77
+ # Every field gets a fast attribute method for immediately persisting
78
+ fast_attribute! name
79
79
  end
80
80
 
81
- # Defines a fast writer method with a bang (!) suffix for a given
82
- # attribute name. Fast writer methods are used to immediately persist
83
- # attribute values to Redis. Calling a fast writer method has no
84
- # effect on any of the object's other attributes and does not trigger
85
- # a called to update the object's expiration time.
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
- # - Checks if the correct number of arguments is provided (exactly one).
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
- # - Persists the value to Redis immediately using the hset command.
92
- # - Includes custom error handling to raise an ArgumentError if the wrong number of arguments is given.
93
- # - Raises a custom error message if an exception occurs during the execution of the method.
94
- #
95
- # @param [Symbol, String] name the name of the attribute for which the writer method is defined.
96
- # @raise [ArgumentError] if the wrong number of arguments is provided.
97
- # @raise [RuntimeError] if an exception occurs during the execution of the method.
98
- #
99
- def fast_writer!(name)
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 != 1
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 "[.fast_writer!] #{name} val: #{val.class} prepared: #{prepared.class}"
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
@@ -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 name, opts
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,
@@ -16,7 +16,7 @@ module Familia
16
16
  extend Familia::Features
17
17
 
18
18
  @registered_types = {}
19
- @valid_options = %i[class parent ttl default db key redis]
19
+ @valid_options = %i[class parent ttl default db key redis suffix]
20
20
  @db = nil
21
21
 
22
22
  feature :expiration
@@ -47,12 +47,12 @@ Familia.debug = false
47
47
  @customer.save
48
48
  #=> true
49
49
 
50
- ## Horreum object fields have a fast writer method (1 of 2)
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 writer method (2 of 2)
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.rc6
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-26 00:00:00.000000000 Z
11
+ date: 2024-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis