Class: Rollout::Redis::Codec
- Inherits:
-
Object
- Object
- Rollout::Redis::Codec
- Defined in:
- lib/rollout/redis/codec.rb
Class Method Summary collapse
- .decode(name, payload) ⇒ Object
- .decode_event(value, score) ⇒ Object
- .encode(feature_state) ⇒ Object
Class Method Details
.decode(name, payload) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rollout/redis/codec.rb', line 10 def self.decode(name, payload) if payload.nil? || payload.empty? return FeatureState.new( name: name, percentage: 0, users: [], groups: [], data: {}, ) end raw_percentage, raw_users, raw_groups, raw_data = payload.split('|', 4) data = raw_data.nil? || raw_data.strip.empty? ? {} : JSON.parse(raw_data) FeatureState.new( name: name, percentage: raw_percentage.to_f, users: (raw_users || '').split(','), groups: (raw_groups || '').split(','), data: data, ) end |
.decode_event(value, score) ⇒ Object
37 38 39 40 41 |
# File 'lib/rollout/redis/codec.rb', line 37 def self.decode_event(value, score) hash = JSON.parse(value, symbolize_names: true) Logging::Event.new(**hash.merge(created_at: Time.at(-score.to_f / 1_000_000))) end |
.encode(feature_state) ⇒ Object
33 34 35 |
# File 'lib/rollout/redis/codec.rb', line 33 def self.encode(feature_state) "#{feature_state.percentage}|#{feature_state.users.join(',')}|#{feature_state.groups.join(',')}|#{feature_state.data.to_json}" end |