ruboty-exec_command 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c22adae587104ba29fd27dea7c0f6d391f5d4db6
4
+ data.tar.gz: b4ab84f740da52a7bc08f6e8974295409ac195bb
5
+ SHA512:
6
+ metadata.gz: 761fa8ddc718ed11e1c0f8effee917c663a3b2e43f7bf9faede6a7f654532e1b154e7c6bbeadf01540500ab7ede514ba1a761dd5adce574ea33463c28bba4768
7
+ data.tar.gz: 9d03859456db4d1124f6a472ae811f4d0dd32f9956e2a6dae0f5cbf88016d8bfa3acdc21ef357cd445d1dbfcae083cb175e7341529dbdb9009891c60f2901d23
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-exec_command.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,39 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), the you will want to move the Guardfile
18
+ ## to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
33
+ # * 'just' rspec: 'rspec'
34
+ guard :rspec, cmd: 'bundle exec rspec' do
35
+ watch(%r{^spec/.+_spec\.rb$})
36
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
37
+ watch('spec/spec_helper.rb') { "spec" }
38
+ end
39
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Nakai Tooru
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,37 @@
1
+ # Ruboty::ExecCommand
2
+
3
+ Ruboty Exec Command adds the name of external command path as a handler.
4
+ You can run your own command from ruboty.
5
+
6
+ Put the command into commands/ directory where your
7
+ bot lives in. The command's path name is used as is handler.
8
+ When you say '@bot: example hello', ruboty runs the command
9
+ $PWD/commands/example/hello or $RUBOTY_ROOT/commands/example/hello
10
+ if RUBOTY_ROOT is defined.
11
+
12
+ For your convinience, please implement -h option into the
13
+ command. The usage will be used for help message of ruboty.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'ruboty-exec_command'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install ruboty-exec_command
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-exec_command/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ echo hello!
@@ -0,0 +1,21 @@
1
+ module Ruboty
2
+ module ExecCommand
3
+ module Actions
4
+ class Command < Ruboty::Actions::Base
5
+ def call
6
+ # TODO: add timeout
7
+ extension = Ruboty::ExecCommand::Command.new(command_args: command_body)
8
+ message.reply(extension.run.chomp)
9
+ end
10
+
11
+ def robot_prefix_pattern
12
+ Ruboty::Action.prefix_pattern(message.original[:robot].name)
13
+ end
14
+
15
+ def command_body
16
+ message.body.sub(robot_prefix_pattern,'')
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,64 @@
1
+ module Ruboty
2
+ module ExecCommand
3
+ class Command
4
+
5
+ class << self
6
+ def command_root
7
+ "#{ENV['RUBOTY_ROOT'] || Dir.pwd}/commands"
8
+ end
9
+
10
+ def command?(path)
11
+ File.executable?(path) and not File.directory?(path)
12
+ end
13
+
14
+ def files
15
+ Dir[command_root+'/**/*'].select do |path|
16
+ command?(path)
17
+ end
18
+ end
19
+
20
+ def all
21
+ files.map do |e|
22
+ Command.new(absolute_path: e)
23
+ end
24
+ end
25
+ end
26
+
27
+ def initialize(args={})
28
+ args = { absolute_path: nil, command_args: nil }.merge(args)
29
+ @absolute_path = args[:absolute_path]
30
+ @command_args = args[:command_args]
31
+ end
32
+
33
+ def absolute_path
34
+ @absolute_path ||= command2path
35
+ end
36
+
37
+ def relative_path
38
+ @relative_path ||= absolute_path.sub(/^#{self.class.command_root}\//,"")
39
+ end
40
+
41
+ def command_args
42
+ @command_args ||= relative_path.gsub('/', ' ')
43
+ end
44
+
45
+ def command2path
46
+ path = self.class.command_root
47
+ @command_args.split(" ").each do |arg|
48
+ path = "#{path}/#{arg}"
49
+ return path if self.class.command?(path)
50
+ end
51
+ ""
52
+ end
53
+
54
+ def run(args=[])
55
+ `#{absolute_path} #{args.join(" ")}`
56
+ end
57
+
58
+ def help
59
+ run(args=['-h']).chomp
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module ExecCommand
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "ruboty/exec_command/command"
2
+ require "ruboty/exec_command/version"
3
+ require "ruboty/handlers/command"
@@ -0,0 +1,24 @@
1
+ require "ruboty/exec_command/actions/command"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class Command < Base
6
+ # Registering commands. Each command is located
7
+ # under "commands" directory. The path name to the
8
+ # executable command is gonna be a command name.
9
+ # i.e. commands/server/monitor => /^server monitor.*/
10
+ # The command should return a usage with -h option
11
+ def self.register_commands
12
+ Ruboty::ExecCommand::Command.all.each do |e|
13
+ on /#{e.command_args}/i, name: "command_handler", description: e.help
14
+ end
15
+ end
16
+
17
+ def command_handler(message)
18
+ Ruboty::ExecCommand::Actions::Command.new(message).call
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Ruboty::Handlers::Command.register_commands
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/exec_command/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-exec_command"
8
+ spec.version = Ruboty::ExecCommand::VERSION
9
+ spec.authors = ["Nakai Tooru"]
10
+ spec.email = ["tr.nakai@gmail.com"]
11
+ spec.summary = %q{Add command to ruboty as a handler}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "ruboty"
22
+ spec.add_runtime_dependency "systemu"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "2.14.1"
26
+ spec.add_development_dependency "guard-rspec"
27
+ spec.add_development_dependency "growl"
28
+ spec.add_development_dependency "simplecov"
29
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ # Specs for class methods
4
+ describe Ruboty::ExecCommand::Command do
5
+ describe "#all" do
6
+ let(:all_commands) do
7
+ Ruboty::ExecCommand::Command.all
8
+ end
9
+
10
+ it "should return an array" do
11
+ expect(all_commands).to be_a(Array)
12
+ end
13
+
14
+ it "should return an array of Extension objects" do
15
+ all_commands.each do |e|
16
+ expect(e).to be_an_instance_of(Ruboty::ExecCommand::Command)
17
+ end
18
+ end
19
+
20
+ it "should contain absolute path" do
21
+ all_commands.each do |e|
22
+ expect(e.absolute_path).to_not eq("")
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ # Specs for instance methods
29
+ describe Ruboty::ExecCommand::Command do
30
+ before do
31
+ ENV['RUBOTY_ROOT'] = "/xxx"
32
+ @e = Ruboty::ExecCommand::Command.new(absolute_path: "/xxx/commands/a/b")
33
+ end
34
+
35
+ describe "#command" do
36
+ it "should return command name" do
37
+ expect(@e.command_args).to eq("a b")
38
+ end
39
+ end
40
+ end
41
+
42
+ describe Ruboty::ExecCommand::Command do
43
+ before do
44
+ ENV['RUBOTY_ROOT'] = Dir.pwd
45
+ @c = Ruboty::ExecCommand::Command.new(command_args: "example hello hoge")
46
+ end
47
+
48
+ describe "#absolute_path" do
49
+ it "should return absolute path" do
50
+ expect(@c.absolute_path).to eq("#{ENV['RUBOTY_ROOT']}/commands/example/hello")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe Ruboty::Handlers::Command do
4
+
5
+ let(:robot) do
6
+ Ruboty::Robot.new
7
+ end
8
+
9
+ let(:from) do
10
+ "alice"
11
+ end
12
+
13
+ let(:to) do
14
+ "#general"
15
+ end
16
+
17
+ let(:said) do
18
+ "@ruboty example hello"
19
+ end
20
+
21
+ let(:replied) do
22
+ "hello!"
23
+ end
24
+
25
+ before do
26
+ ENV['RUBOTY_ROOT'] = Dir.pwd
27
+ end
28
+
29
+ describe "#command_handler" do
30
+ it "run example command" do
31
+ robot.should_receive(:say).with(
32
+ body: replied,
33
+ from: to,
34
+ to: from,
35
+ original: {
36
+ body: said,
37
+ from: from,
38
+ robot: robot,
39
+ to: to,
40
+ },
41
+ )
42
+ robot.receive(body: said, from: from, to: to)
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,19 @@
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ ENV["RUBOTY_ENV"] = "test"
5
+
6
+ if ENV["CI"]
7
+ require "codeclimate-test-reporter"
8
+ CodeClimate::TestReporter.start
9
+ end
10
+
11
+ require "active_support/core_ext/string/strip"
12
+ require "ruboty"
13
+ require "ruboty/exec_command"
14
+
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-exec_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Nakai Tooru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-25 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: systemu
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: growl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: ''
126
+ email:
127
+ - tr.nakai@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - Guardfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - commands/example/hello
139
+ - lib/ruboty/exec_command.rb
140
+ - lib/ruboty/exec_command/actions/command.rb
141
+ - lib/ruboty/exec_command/command.rb
142
+ - lib/ruboty/exec_command/version.rb
143
+ - lib/ruboty/handlers/command.rb
144
+ - ruboty-exec_command.gemspec
145
+ - spec/lib/ruboty/exec-command/command_spec.rb
146
+ - spec/lib/ruboty/handlers/command_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: ''
149
+ licenses:
150
+ - MIT
151
+ metadata: {}
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 2.0.14
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Add command to ruboty as a handler
172
+ test_files:
173
+ - spec/lib/ruboty/exec-command/command_spec.rb
174
+ - spec/lib/ruboty/handlers/command_spec.rb
175
+ - spec/spec_helper.rb