Class: Conflow::Redis::HashField Private
- Includes:
- Enumerable
- Defined in:
- lib/conflow/redis/hash_field.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents Redis hash. It’s methods mirror most used Hash methods.
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
private
True if equal.
-
#each(&block) ⇒ Enumerator
private
Iterates over hash.
-
#merge(hash) ⇒ String
private
Merges hashes, similar to Hash#merge.
-
#overwrite(new_hash) ⇒ String
private
Replaces currently stored hash with one given as param.
-
#to_h ⇒ String
(also: #to_hash)
private
Creates Ruby Hash based on soted values.
-
#to_s ⇒ String
private
String representation of the hash.
Methods inherited from Field
Constructor Details
This class inherits a constructor from Conflow::Redis::Field
Instance Method Details
#==(other) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if equal.
55 56 57 58 59 60 61 |
# File 'lib/conflow/redis/hash_field.rb', line 55 def ==(other) case other when Hash then to_h == other when HashField then key == other.key || to_h == other.to_h else super end end |
#each(&block) ⇒ Enumerator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Iterates over hash.
49 50 51 |
# File 'lib/conflow/redis/hash_field.rb', line 49 def each(&block) to_h.each(&block) end |
#merge(hash) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Merges hashes, similar to Hash#merge
16 17 18 |
# File 'lib/conflow/redis/hash_field.rb', line 16 def merge(hash) command :hmset, [key, hash.flatten] end |
#overwrite(new_hash) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Replaces currently stored hash with one given as param
26 27 28 29 30 31 32 33 |
# File 'lib/conflow/redis/hash_field.rb', line 26 def overwrite(new_hash) redis.with do |conn| conn.pipelined do conn.del(key) conn.hmset(key, prepare_hash(new_hash).flatten) end end end |
#to_h ⇒ String Also known as: to_hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates Ruby Hash based on soted values. Keys will be symbolized and values JSON-parsed
40 41 42 43 44 |
# File 'lib/conflow/redis/hash_field.rb', line 40 def to_h command(:hgetall, [key]).each_with_object({}) do |(key, value), hash| hash[key.to_sym] = JSON.parse(value) end end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns string representation of the hash.
64 65 66 |
# File 'lib/conflow/redis/hash_field.rb', line 64 def to_s to_h.to_s end |