Class: RedisScanner::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_scanner/rule.rb

Constant Summary collapse

PRESET_RULES =
[
  [/(:\d+:)/, ":<id>:"],
  [/(:\w{8}-\w{4}-\w{4}-\w{4}-\w{12}:)/, ":<uuid>:"],
  [/(:\d{4}-\d{2}-\d{2}:)/, ":<date>:"],
  [/(:\d+)$/, ":<id>"],
  [/(:\w{8}-\w{4}-\w{4}-\w{4}-\w{12})$/, ":<uuid>"],
  [/(:\d{4}-\d{2}-\d{2})$/, ":<date>"]
]

Instance Method Summary collapse

Constructor Details

#initializeRule

Returns a new instance of Rule.



14
15
16
# File 'lib/redis_scanner/rule.rb', line 14

def initialize
  @rules = PRESET_RULES
end

Instance Method Details

#extract_pattern(key) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/redis_scanner/rule.rb', line 18

def extract_pattern(key)
  key = force_valid_key(key)
  @rules.each do |rule, replacer|
    while (m = rule.match(key))
      key = key.sub(m[1], replacer)
    end
  end
  key
end