ruboty-help_query 1.0.0

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: e9d64c210a295a62c8ab58fb752a2e5112db8f55
4
+ data.tar.gz: 4c12fd8389a3f72f2f777e5d503715c539c19ec8
5
+ SHA512:
6
+ metadata.gz: 40d33681c5b44b76a84a3d18576ce7b5f568509994ab0c31dfd67d8087343c2d729785260ad117f32b8719eafd08176354c20e2558db468543594b6a9074183b
7
+ data.tar.gz: 2d27183bb1efad5abc8082432c300e5bbaa46eaa4745380e1f4951eedc405b71966b08b4eeb1b926b3766c98b2502ed61a244c7f8b0678427c9ad0157c8fdd03
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/FormatString:
2
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system 2.1.11
4
+ - gem --version
5
+ rvm:
6
+ - 2.0.0
7
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-help_query.gemspec
4
+ gemspec
5
+ gem 'simplecov', '~> 0.8.2'
6
+ group :test do
7
+ gem 'coveralls', require: false
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tbpgr
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,64 @@
1
+ # Ruboty::HelpQuery
2
+
3
+ An Ruboty Handler + Actions to show all help commands that match <query>.
4
+
5
+ [![Build Status](https://travis-ci.org/tbpgr/ruboty-help_query.png?branch=master)](https://travis-ci.org/tbpgr/ruboty-help_query)
6
+ [![Coverage Status](https://coveralls.io/repos/tbpgr/ruboty-help_query/badge.png)](https://coveralls.io/r/tbpgr/ruboty-help_query)
7
+
8
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ruboty-help_query'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ruboty-help_query
25
+
26
+
27
+ ## Commands
28
+
29
+ |Command|Pattern|Description|
30
+ |:--|:--|:--|
31
+ |help|/help *(?<query>.*)\z/|Show all help commands that match <query>.|
32
+
33
+ ## Usage
34
+ ### help
35
+ * Show all help commands that match <query>.
36
+
37
+ ~~~
38
+ >ruboty help ping
39
+ >ruboty /ping\\z/i - Return PONG to PING
40
+ >
41
+ >ruboty help .*p.*
42
+ >ruboty /help( me)?\\z/i - Show this help message
43
+ >ruboty /ping\\z/i - Return PONG to PING
44
+ ~~~
45
+
46
+ ## ENV
47
+
48
+ |Name|Description|
49
+ |:--|:--|
50
+ |--|--|
51
+
52
+ ## Dependency
53
+
54
+ |Name|Description|
55
+ |:--|:--|
56
+ |--|--|
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/tbpgr/ruboty-help_query/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+ task default: [:spec]
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ end
@@ -0,0 +1,18 @@
1
+ require 'ruboty/help_query/actions/help'
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ # HelpQuery
6
+ class HelpQuery < Base
7
+ on(
8
+ /help\s*(?<query>.*)\z/,
9
+ name: 'help',
10
+ description: 'Show all help commands that match <query>.'
11
+ )
12
+
13
+ def help(message)
14
+ Ruboty::HelpQuery::Actions::Help.new(message).call
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,35 @@
1
+ # rubocop:disable LineLength, MethodLength
2
+ module Ruboty
3
+ module HelpQuery
4
+ module Actions
5
+ # Help
6
+ class Help < Ruboty::Actions::Base
7
+ def call
8
+ message.reply(help)
9
+ end
10
+
11
+ private
12
+
13
+ def help
14
+ Ruboty.actions.reject(&:hidden?)
15
+ .select { |action|action.pattern.to_s =~ /#{message[:query]}/ }
16
+ .sort
17
+ .map do |action|
18
+ prefix = ''
19
+ prefix << message.robot.name << ' ' unless action.all?
20
+ pattern_format = "%-#{pattern_max_length + prefix.size}s"
21
+ pattern_text = "#{prefix}#{action.pattern.inspect}"
22
+ "#{pattern_format} - #{action.description}" % pattern_text
23
+ end.join("\n")
24
+ rescue => e
25
+ "Error: #{e.message}"
26
+ end
27
+
28
+ def pattern_max_length
29
+ Ruboty.actions.map { |action| action.pattern.inspect }.map(&:size).max
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ # rubocop:enable LineLength, MethodLength
@@ -0,0 +1,6 @@
1
+ module Ruboty
2
+ # HelpQuery
3
+ module HelpQuery
4
+ VERSION = '1.0.0'
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ require 'ruboty'
2
+ require 'ruboty/help_query/version'
3
+ require 'ruboty/handlers/help_query'
4
+
5
+ module Ruboty
6
+ # HelpQuery
7
+ module HelpQuery
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/help_query/version'
5
+
6
+ # rubocop:disable LineLength
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ruboty-help_query'
9
+ spec.version = Ruboty::HelpQuery::VERSION
10
+ spec.authors = ['tbpgr']
11
+ spec.email = ['tbpgr@tbpgr.jp']
12
+ spec.summary = 'An Ruboty Handler + Actions to show all help commands that match <query>.'
13
+ spec.description = 'An Ruboty Handler + Actions to show all help commands that match <query>.'
14
+ spec.homepage = 'https://github.com/tbpgr/ruboty-help_query'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'ruboty'
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'simplecov'
27
+ end
28
+ # rubocop:enable LineLength
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty/handlers/help_query'
4
+ require 'ruboty/help_query/actions/help'
5
+
6
+ # rubocop:disable LineLength, UnusedMethodArgument
7
+ describe Ruboty::Handlers::HelpQuery do
8
+ context :help do
9
+ let(:robot) do
10
+ Ruboty::Robot.new
11
+ end
12
+
13
+ let(:help) do
14
+ Ruboty::HelpQuery::Actions::Help
15
+ end
16
+
17
+ cases = [
18
+ {
19
+ case_no: 1,
20
+ case_title: 'exist id case',
21
+ body: 'ruboty help *p*',
22
+ expected: 'expected message',
23
+ hit: true
24
+ },
25
+ {
26
+ case_no: 2,
27
+ case_title: 'not hit message case',
28
+ body: 'ruboty nothit *p*',
29
+ expected: 'expected message',
30
+ hit: false
31
+ }
32
+ ]
33
+
34
+ cases.each do |c|
35
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
36
+ begin
37
+ case_before c
38
+
39
+ # -- given --
40
+ allow_any_instance_of(help).to receive(:help).and_return(c[:expected])
41
+
42
+ # -- then --
43
+ if c[:hit]
44
+ Ruboty.logger.should_receive(:info).with(c[:expected])
45
+ else
46
+ Ruboty.logger.should_not_receive(:info)
47
+ end
48
+
49
+ # -- when --
50
+ robot.receive(body: c[:body], from: 'sender', to: 'channel')
51
+ ensure
52
+ case_after c
53
+ end
54
+ end
55
+
56
+ def case_before(_c)
57
+ # implement each case before
58
+ end
59
+
60
+ def case_after(_c)
61
+ # implement each case after
62
+ end
63
+ end
64
+ end
65
+ end
66
+ # rubocop:enable LineLength, UnusedMethodArgument
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'ruboty'
4
+ require 'ruboty/help_query/actions/help'
5
+
6
+ # rubocop:disable LineLength, UnusedMethodArgument
7
+ describe Ruboty::HelpQuery::Actions::Help do
8
+ context :help do
9
+ let(:message) do
10
+ # Dummy Robot
11
+ class Robot
12
+ attr_accessor :name
13
+ def initialize(name)
14
+ @name = name
15
+ end
16
+ end
17
+ # Dummy Message
18
+ class Message < Hash
19
+ def robot
20
+ Robot.new('robot')
21
+ end
22
+
23
+ def reply(message)
24
+ message
25
+ end
26
+ end
27
+ Message.new
28
+ end
29
+
30
+ cases = [
31
+ {
32
+ case_no: 1,
33
+ case_title: 'exist user case',
34
+ query: '.*p.*',
35
+ expected: <<-EOS
36
+ robot /help\\s*(?<query>.*)\\z/ - Show all help commands that match <query>.
37
+ robot /help( me)?\\z/i - Show this help message
38
+ robot /ping\\z/i - Return PONG to PING
39
+ EOS
40
+ },
41
+ {
42
+ case_no: 2,
43
+ case_title: 'not exist user case',
44
+ query: 'ping',
45
+ expected: <<-EOS
46
+ robot /ping\\z/i - Return PONG to PING
47
+ EOS
48
+ }
49
+ ]
50
+
51
+ cases.each do |c|
52
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
53
+ begin
54
+ case_before c
55
+
56
+ # -- given --
57
+ message.robot.name = 'sample'
58
+ message[:query] = c[:query]
59
+ action = Ruboty::HelpQuery::Actions::Help.new(message)
60
+
61
+ # -- when --
62
+ actual = action.send(:help)
63
+
64
+ # -- then --
65
+ expect(actual).to eq(c[:expected].chomp)
66
+ ensure
67
+ case_after c
68
+ end
69
+ end
70
+
71
+ def case_before(_c)
72
+ # implement each case before
73
+ end
74
+
75
+ def case_after(_c)
76
+ # implement each case after
77
+ end
78
+ end
79
+ end
80
+ end
81
+ # rubocop:enable LineLength, UnusedMethodArgument
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ Coveralls.wear!
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter '/spec/'
11
+ end
12
+ require 'ruboty/help_query'
13
+ RSpec.configure do |config|
14
+ config.treat_symbols_as_metadata_keys_with_true_values = true
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-help_query
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-08 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: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: An Ruboty Handler + Actions to show all help commands that match <query>.
84
+ email:
85
+ - tbpgr@tbpgr.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .coveralls.yml
91
+ - .gitignore
92
+ - .rspec
93
+ - .rubocop.yml
94
+ - .travis.yml
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - lib/ruboty/handlers/help_query.rb
100
+ - lib/ruboty/help_query.rb
101
+ - lib/ruboty/help_query/actions/help.rb
102
+ - lib/ruboty/help_query/version.rb
103
+ - ruboty-help_query.gemspec
104
+ - spec/ruboty/handlers/help_query_spec.rb
105
+ - spec/ruboty/help_query/actions/help_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/tbpgr/ruboty-help_query
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.3.0
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: An Ruboty Handler + Actions to show all help commands that match <query>.
131
+ test_files:
132
+ - spec/ruboty/handlers/help_query_spec.rb
133
+ - spec/ruboty/help_query/actions/help_spec.rb
134
+ - spec/spec_helper.rb