Class: Lita::Alias::AliasStore
- Inherits:
-
Object
- Object
- Lita::Alias::AliasStore
- Defined in:
- lib/lita/alias/alias_store.rb
Overview
Repository of aliases. Stores the aliases in a hash in redis keyed by the alias name
Defined Under Namespace
Classes: AliasAddException, AliasNotFoundException
Constant Summary collapse
- STORE_KEY =
'aliases'
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#add(aliased_command) ⇒ Object
Store the alias.
-
#delete(name) ⇒ Object
Delete the alias with name.
- #exists?(name) ⇒ Boolean
-
#initialize(redis) ⇒ AliasStore
constructor
A new instance of AliasStore.
-
#list ⇒ Object
Return a list of all aliases.
- #lookup(name) ⇒ Object
Constructor Details
#initialize(redis) ⇒ AliasStore
Returns a new instance of AliasStore.
9 10 11 |
# File 'lib/lita/alias/alias_store.rb', line 9 def initialize(redis) @redis = redis end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
7 8 9 |
# File 'lib/lita/alias/alias_store.rb', line 7 def redis @redis end |
Instance Method Details
#add(aliased_command) ⇒ Object
Store the alias.
25 26 27 28 29 |
# File 'lib/lita/alias/alias_store.rb', line 25 def add(aliased_command) fail AliasAddException, "The alias is not valid" unless aliased_command.valid? @redis.hset(STORE_KEY, aliased_command.name, aliased_command.command) end |
#delete(name) ⇒ Object
Delete the alias with name
14 15 16 17 18 19 20 |
# File 'lib/lita/alias/alias_store.rb', line 14 def delete(name) fail AliasNotFoundException, "No alias with name #{name} exists" unless @redis.hexists(STORE_KEY, name) command = @redis.hget(STORE_KEY, name) @redis.hdel(STORE_KEY, name) AliasedCommand.new(name, command).freeze end |
#exists?(name) ⇒ Boolean
44 45 46 |
# File 'lib/lita/alias/alias_store.rb', line 44 def exists?(name) @redis.hexists(STORE_KEY, name) end |
#list ⇒ Object
Return a list of all aliases
33 34 35 36 37 |
# File 'lib/lita/alias/alias_store.rb', line 33 def list @redis.hgetall(STORE_KEY).sort.map do |name, command| AliasedCommand.new(name, command) end end |
#lookup(name) ⇒ Object
39 40 41 42 |
# File 'lib/lita/alias/alias_store.rb', line 39 def lookup(name) command = @redis.hget(STORE_KEY, name) AliasedCommand.new(name, command) end |