ellen-alias 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 595894dd73200a5fe967d4a7e0bca4131e6f38e5
4
+ data.tar.gz: 8c634389fe0f5c187f9869d021d18bcd33c463d6
5
+ SHA512:
6
+ metadata.gz: 0814c67192f0667b8f0b69cc7c239e49d9a53e5e8cf0137b3e70a02dfedc19c6756dcaa8a885a91c1b95dc0d19c3e6bcc9557e78717fe8bbb76a3aa344ba7668
7
+ data.tar.gz: dd7c5d4f1c844517f566a74b822a655a0f2de640855d558aa53f8a578b881bb759efce7582a11917be8c025a69705d7dded45c3236cd974367d6b774bc393d61
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ellen-alias.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryo Nakamura
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Ellen::Alias
2
+ Remember message alias.
3
+
4
+ ## Install
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ellen-alias"
8
+ ```
9
+
10
+ ## Usage
11
+ ```
12
+ @ellen alias p -> ping - Register "p" as "ping"
13
+ @ellen p - Recognize "p" as "ping"
14
+ @ellen list alias - List registered aliases
15
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ellen/alias/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ellen-alias"
7
+ spec.version = Ellen::Alias::VERSION
8
+ spec.authors = ["Ryo Nakamura"]
9
+ spec.email = ["r7kamura@gmail.com"]
10
+ spec.summary = "Remember message alias."
11
+ spec.homepage = "https://github.com/r7kamura/ellen-alias"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ellen", ">= 0.2.4"
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,2 @@
1
+ require "ellen/alias/version"
2
+ require "ellen/handlers/alias"
@@ -0,0 +1,5 @@
1
+ module Ellen
2
+ module Alias
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ module Ellen
2
+ module Handlers
3
+ class Alias < Base
4
+ NAMESPACE = "alias"
5
+
6
+ on(
7
+ /alias (?<from>.+) -> (?<to>.+)\z/,
8
+ description: "Create alias message",
9
+ name: "create",
10
+ )
11
+
12
+ on(
13
+ /list alias\z/,
14
+ description: "List alias",
15
+ name: "list",
16
+ )
17
+
18
+ on(
19
+ //,
20
+ description: "Resolve alias if registered",
21
+ name: "resolve",
22
+ hidden: true,
23
+ )
24
+
25
+ def create(message)
26
+ from = message[:from]
27
+ to = message[:to]
28
+ table[from] = to
29
+ message.reply("Registered alias: #{from} -> #{to}")
30
+ end
31
+
32
+ def list(message)
33
+ message.reply(aliases, code: true)
34
+ end
35
+
36
+ def resolve(message)
37
+ from = message.body.gsub(prefix, "")
38
+ if aliased = table[from]
39
+ robot.receive(
40
+ message.original.merge(
41
+ body: "#{message.body[prefix]}#{aliased}"
42
+ )
43
+ )
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def table
50
+ robot.brain.data[NAMESPACE] ||= {}
51
+ end
52
+
53
+ def aliases
54
+ if table.empty?
55
+ "No alias registered"
56
+ else
57
+ table.map {|from, to| "%-#{max_from_length}s -> #{to}" % from }.join("\n")
58
+ end
59
+ end
60
+
61
+ def max_from_length
62
+ table.keys.map(&:length).max
63
+ end
64
+
65
+ def prefix
66
+ Ellen::Action.prefix_pattern(robot.name)
67
+ end
68
+ end
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ellen-alias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ellen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - r7kamura@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - ellen-alias.gemspec
68
+ - lib/ellen/alias.rb
69
+ - lib/ellen/alias/version.rb
70
+ - lib/ellen/handlers/alias.rb
71
+ homepage: https://github.com/r7kamura/ellen-alias
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Remember message alias.
95
+ test_files: []
96
+ has_rdoc: