ruboty-alias 0.0.3

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: 41ea520b728538ef60084dd182a3d8fd5f86e889
4
+ data.tar.gz: bd46078d1504d7258953553bdfd73ac951f36b23
5
+ SHA512:
6
+ metadata.gz: d4bcffadf39e661e425ce97db99462a99716286ac956cd8e57c4d9b225c5201f7e8c1ef99216a94e627d8a2c0ec36d93e83c120ca6c8cea5f3a0322a905ed01e
7
+ data.tar.gz: 49faa4fe65f5b6d185f8b667740360d0cc4afcb439ea755011bcc0f55907cfb7fe42ddc4d3dc0a5cff10c7ad7abc30f4428785cdb44c5d292c6f06ff9881972f
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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.0.3
2
+ * Rename: Ellen -> Ruboty
3
+
4
+ ## 0.0.2
5
+ * Add a command to delete alias
6
+
7
+ ## 0.0.1
8
+ * 1st Release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-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,16 @@
1
+ # Ruboty::Alias
2
+ Remember message alias.
3
+
4
+ ## Install
5
+ ```ruby
6
+ # Gemfile
7
+ gem "ruboty-alias"
8
+ ```
9
+
10
+ ## Usage
11
+ ```
12
+ @ruboty alias p -> ping - Register "p" as "ping"
13
+ @ruboty p - Recognize "p" as "ping"
14
+ @ruboty list alias - List registered aliases
15
+ @ruboty delete alias - Delete registered alias
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,2 @@
1
+ require "ruboty/alias/version"
2
+ require "ruboty/handlers/alias"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Alias
3
+ VERSION = "0.0.3"
4
+ end
5
+ end
@@ -0,0 +1,84 @@
1
+ module Ruboty
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
+ /delete alias (?<from>.+)\z/,
20
+ description: "Delete alias",
21
+ name: "delete",
22
+ )
23
+
24
+ on(
25
+ //,
26
+ description: "Resolve alias if registered",
27
+ name: "resolve",
28
+ hidden: true,
29
+ )
30
+
31
+ def create(message)
32
+ from = message[:from]
33
+ to = message[:to]
34
+ table[from] = to
35
+ message.reply("Registered alias: #{from} -> #{to}")
36
+ end
37
+
38
+ def delete(message)
39
+ if table.delete(message[:from])
40
+ message.reply("Deleted")
41
+ else
42
+ message.reply("Not found")
43
+ end
44
+ end
45
+
46
+ def list(message)
47
+ message.reply(aliases, code: true)
48
+ end
49
+
50
+ def resolve(message)
51
+ from = message.body.gsub(prefix, "")
52
+ if aliased = table[from]
53
+ robot.receive(
54
+ message.original.merge(
55
+ body: "#{message.body[prefix]}#{aliased}"
56
+ )
57
+ )
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def table
64
+ robot.brain.data[NAMESPACE] ||= {}
65
+ end
66
+
67
+ def aliases
68
+ if table.empty?
69
+ "No alias registered"
70
+ else
71
+ table.map {|from, to| "%-#{max_from_length}s -> #{to}" % from }.join("\n")
72
+ end
73
+ end
74
+
75
+ def max_from_length
76
+ table.keys.map(&:length).max
77
+ end
78
+
79
+ def prefix
80
+ Ruboty::Action.prefix_pattern(robot.name)
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "ruboty/alias/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-alias"
7
+ spec.version = Ruboty::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/ruboty-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 "ruboty"
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-alias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/ruboty/alias.rb
69
+ - lib/ruboty/alias/version.rb
70
+ - lib/ruboty/handlers/alias.rb
71
+ - ruboty-alias.gemspec
72
+ homepage: https://github.com/r7kamura/ruboty-alias
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Remember message alias.
96
+ test_files: []
97
+ has_rdoc: