Class: SimpleFeed::Providers::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/simplefeed/providers/key.rb

Overview

Here is a meta key for a given user ID:

   user   'm' for meta
     ↓        ↓
 "ff|u.f23098.m"
  ↑         ↑
namespace consumer(base62)

Constant Summary collapse

SERIALIZED_DATA_TEMPLATE =
'{{namespace}}u.{{data_id}}.d'
SERIALIZED_META_TEMPLATE =
'{{namespace}}u.{{meta_id}}.m'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, namespace: nil, data_key_transformer: nil, meta_key_transformer: nil) ⇒ Key

Returns a new instance of Key.



29
30
31
32
33
34
35
36
37
# File 'lib/simplefeed/providers/key.rb', line 29

def initialize(consumer,
               namespace: nil,
               data_key_transformer: nil,
               meta_key_transformer: nil)
  @consumer = consumer
  @namespace = namespace
  @data_key_transformer = data_key_transformer
  @meta_key_transformer = meta_key_transformer
end

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



27
28
29
# File 'lib/simplefeed/providers/key.rb', line 27

def consumer
  @consumer
end

#data_key_transformerObject (readonly)

Returns the value of attribute data_key_transformer.



27
28
29
# File 'lib/simplefeed/providers/key.rb', line 27

def data_key_transformer
  @data_key_transformer
end

#meta_key_transformerObject (readonly)

Returns the value of attribute meta_key_transformer.



27
28
29
# File 'lib/simplefeed/providers/key.rb', line 27

def meta_key_transformer
  @meta_key_transformer
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



27
28
29
# File 'lib/simplefeed/providers/key.rb', line 27

def namespace
  @namespace
end

Class Method Details

.rot13(value) ⇒ Object



18
19
20
21
# File 'lib/simplefeed/providers/key.rb', line 18

def rot13(value)
  value.tr('abcdefghijklmnopqrstuvwxyz',
           'nopqrstuvwxyzabcdefghijklm')
end

Instance Method Details

#dataObject



39
40
41
# File 'lib/simplefeed/providers/key.rb', line 39

def data
  @data ||= render(SERIALIZED_DATA_TEMPLATE)
end

#inspectObject



55
56
57
# File 'lib/simplefeed/providers/key.rb', line 55

def inspect
  super + key_params.inspect
end

#keysObject



47
48
49
# File 'lib/simplefeed/providers/key.rb', line 47

def keys
  [data, meta]
end

#metaObject



43
44
45
# File 'lib/simplefeed/providers/key.rb', line 43

def meta
  @meta ||= render(SERIALIZED_META_TEMPLATE)
end

#to_sObject



51
52
53
# File 'lib/simplefeed/providers/key.rb', line 51

def to_s
  super + key_params.to_s
end