Class: SimpleFeed::Providers::Serialization::Key
- Inherits:
-
Object
- Object
- SimpleFeed::Providers::Serialization::Key
- Defined in:
- lib/simplefeed/providers/serialization/key.rb
Constant Summary collapse
- KEY_CONFIG =
This hash defines the paramters for the strategy we use to create a compact key based on the user id, feed’s namespace, and the functionality, such as ‘m’ meta — as a hash for storing arbitrary values (in particular,
last_read). and ‘d’ data —as a sorted set in for storing the actual events.### Examples
Here is a meta key for a given user ID:
user 'm' for Hashie::Mash.new({ separator: '.', prefix: '', namespace_divider: '|', namespace: nil, primary: ->(user_id) { ::Base62.encode(user_id) }, primary_marker: 'u', secondary_markers: { data: 'd', meta: 'm' } })
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#short_id ⇒ Object
Returns the value of attribute short_id.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Instance Method Summary collapse
- #for(type) ⇒ Object
-
#initialize(user_id, namespace = nil, optional_key_config = {}) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #keys ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(user_id, namespace = nil, optional_key_config = {}) ⇒ Key
Returns a new instance of Key.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 38 def initialize(user_id, namespace = nil, optional_key_config = {}) optional_key_config.merge!(namespace: namespace) if namespace self.config = KEY_CONFIG.dup.merge!(optional_key_config) self.user_id = user_id self.short_id = config.primary[user_id] self.prefix = configure_prefix config.secondary_markers.each_pair do |type, character| self.class.send(:define_method, type) do instance_variable_get("@#{type}") || instance_variable_set("@#{type}", "#{prefix}#{config.separator}#{character}") end end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 7 def config @config end |
#prefix ⇒ Object
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 7 def prefix @prefix end |
#short_id ⇒ Object
Returns the value of attribute short_id.
7 8 9 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 7 def short_id @short_id end |
#user_id ⇒ Object
Returns the value of attribute user_id.
7 8 9 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 7 def user_id @user_id end |
Instance Method Details
#for(type) ⇒ Object
58 59 60 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 58 def for(type) "#{prefix}#{config.separator}#{type.to_s}" end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 66 def inspect end |
#keys ⇒ Object
54 55 56 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 54 def keys config.secondary_markers.map { |k, v| [k, self.send(k)] } end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/simplefeed/providers/serialization/key.rb', line 62 def to_s super.gsub(/SimpleFeed::Providers::Serialization/, '...*') + { user_id: user_id, short_id: short_id, keys: keys }.to_json end |