Class: Ruboty::Handlers::FlexibleAlias
- Inherits:
-
Base
- Object
- Base
- Ruboty::Handlers::FlexibleAlias
- Defined in:
- lib/ruboty/handlers/flexible_alias.rb
Constant Summary collapse
- NAMESPACE =
'flexible_alias'.freeze
Instance Method Summary collapse
- #create(message) ⇒ Object
- #create_scoped(message) ⇒ Object
- #delete(message) ⇒ Object
- #list(message) ⇒ Object
- #resolve(message) ⇒ Object
Instance Method Details
#create(message) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ruboty/handlers/flexible_alias.rb', line 39 def create() from = [:original] to = [:alias] register('*', from, to) .reply("Registered alias: #{from} -> #{to}") end |
#create_scoped(message) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/ruboty/handlers/flexible_alias.rb', line 46 def create_scoped() scope = .from from = [:original] to = [:alias] register(scope, from, to) .reply("Registered alias: #{from} -> #{to}") end |
#delete(message) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruboty/handlers/flexible_alias.rb', line 54 def delete() scope = .from if (table[scope] || {}).delete([:alias]) .reply('Deleted') else if (table['*'] || {}).delete([:alias]) .reply('Deleted') else .reply('Not found') end end end |
#list(message) ⇒ Object
67 68 69 |
# File 'lib/ruboty/handlers/flexible_alias.rb', line 67 def list() .reply(aliases(.from), code: true) end |
#resolve(message) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruboty/handlers/flexible_alias.rb', line 71 def resolve() scope = .from scoped = table[scope] || {} all = table['*'] || {} from = .body.gsub(prefix, '') hit = false all.merge(scoped).each_pair do |pattern, transformed| alias_cmd = Ruboty::FlexibleAlias::Alias.new(pattern, transformed) next unless aliased = alias_cmd.tranfrom(from) robot.receive( .original.merge( body: "#{.body[prefix]}#{aliased}" ) ) hit = true break end hit end |