slappy 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f6569438c773c309cbc6946bb9b25dcb60dc59d
4
- data.tar.gz: 31f3eeee45abc61e2ca093d9ae7fbab63e5e055a
3
+ metadata.gz: 8e79a1760b63ef1b9dc0b47ddc653346f56d972f
4
+ data.tar.gz: 081b83f1f491f9173a1fd25f085c42faed243013
5
5
  SHA512:
6
- metadata.gz: 27ff356c54218c17816ab23e147c364dabfced2f567fe3e9cc91255ae60ede45582d2a19ab4fc848e4b7787e20eacd7ee13022181c9f173df07094178792dc5a
7
- data.tar.gz: 609792027661024892179ce92f058c491fae2cb8bb6b05c57b06010ec0f047c79a8b7c9bc9ebe39cba8a17b9fb56ad62c833f4b6cb0f8c1b7ce0c83ef5752025
6
+ metadata.gz: c5b60c4a6050e4df1e15f5f0d8ddd3a544edbf69669c18148dd505e05ddd152041dd14acfd662db472d73338ca32347a54cd409cdfee0e232a72374f0c78ed6b
7
+ data.tar.gz: af1e4362d1387b85cc69e7492ed88b9b2f0f0a8e5bae0fd8eb042c2762742b597ad90c1cc4f3fddfb01db993d293742ed575173d3eddc9af1a2da81124edfecd
data/.hound.yml CHANGED
@@ -15,6 +15,12 @@ Style/Documentation:
15
15
  Style/StringLiterals:
16
16
  EnforcedStyle: single_quotes
17
17
 
18
+ ##################### Lint ##################################
19
+
20
+ Lint/UnusedBlockArgument:
21
+ Exclude:
22
+ - 'templates/slappy_config.rb'
23
+
18
24
  ##################### Metrics ##################################
19
25
 
20
26
  Metrics/AbcSize:
data/.travis.yml CHANGED
@@ -12,9 +12,6 @@ before_script:
12
12
  script:
13
13
  - ruby --version
14
14
  - bundle exec rspec
15
- branches:
16
- only:
17
- - master
18
15
  notifications:
19
16
  slack:
20
17
  secure: ocTnQAT5/a3gu93ZZ0vinihMT6/NG3fp4pV2li9WSJRuImFwSTI2eAmjlOZbk/SaZIdj2alGIB2HqMH6sHFheCiUSuAzf+8aaGvBwFh//x+2uibXccoyZLIUoDb5OMHCZSilkQgx8MtsGsPCr+7ryvclxIL+3YJz2NjTpwPPoLsXUNXXzaJtYHknb62BCGGTC5wz8J5JOVKloDXVz4F2CMZqX2ylM/DxFTl5LI94kT/7pv7KfelCHsm6R0F4ALaJT0zumx+t/QAlezzlvRqu81L76yPlEgdahydY77yd7xVqUOEhvNEEiriHMR/+4xYMEieVvERlDLsk4kvywX6YbGId/5tDaQvRIkHIN/9XeKnt/DyMbBVugC0MtZGbNREtD2a9u85V0Zzv/ufBva3FHtbWsHXBtETrb3ty9yrplDkqg/H9vOfISfnSYxOk8F56DMj0h6QSaocCk/9hk31C2I66ZvmmJC5LkSNN77KFT0u32nSFAi5Maj3FhGGW2eXg/jWqBjjyYqUQtjeQguqhtPna5QSpmY17a6l7LAujoQ/romkiEIW+Qwd2tPv53DVe5q1fWNTSrr5LVhkKjkATAWlKLv8oJOj86/EcaoNCZFS7mufq16hDMW9UJbEsuqguRCZKR49FC/U80NWwx+jrkzHY41Meh6yeYd5JQyODb9E=
data/README.md CHANGED
@@ -43,6 +43,7 @@ Example:
43
43
  ```ruby
44
44
  # catch pattern
45
45
  hear '^hello, slappy!' do |event|
46
+ logger.info 'received message!'
46
47
  say 'hello!!', channel: event.channel #=> respond message to channel
47
48
  end
48
49
  ```
@@ -122,22 +123,22 @@ require 'slappy'
122
123
 
123
124
  # called when start up
124
125
  Slappy.hello do
125
- puts 'successfly connected'
126
+ Slappy.logger.info 'successfly connected'
126
127
  end
127
128
 
128
129
  # called when match message
129
130
  Slappy.hear 'foo' do
130
- puts 'foo'
131
+ Slappy.logger.info 'foo'
131
132
  end
132
133
 
133
134
  # use regexp in string literal
134
135
  Slappy.hear 'bar (.*)' do |event|
135
- puts event.matches[1] #=> Event#matches return MatchData object
136
+ Slappy.logger.info event.matches[1] #=> Event#matches return MatchData object
136
137
  end
137
138
 
138
139
  # event object is slack event JSON (convert to Hashie::Mash)
139
140
  Slappy.hear '^bar (.*)' do |event|
140
- puts event.channel #=> channel id
141
+ Slappy.logger.info event.channel #=> channel id
141
142
  Slappy.say 'slappy!', channel: event.channel #=> to received message channel
142
143
  Slappy.say 'slappy!', channel: '#general'
143
144
  Slappy.say 'slappy!', username: 'slappy!', icon_emoji: ':slappy:'
@@ -145,12 +146,35 @@ end
145
146
 
146
147
  # use regexp literal
147
148
  Slappy.hear /^foobar/ do
148
- puts 'slappppy!'
149
+ Slappy.logger.info 'slappppy!'
149
150
  end
150
151
 
151
152
  Slappy.start #=> Start slappy process
152
153
  ```
153
154
 
155
+ ## Release Note
156
+
157
+ - v0.4.0
158
+ - Support logger
159
+ - Support load lib directory
160
+ - Add New command
161
+ - version
162
+ - Choise dsl enabled in slappy_config
163
+
164
+ - v0.3.0
165
+ - Introduce DSL
166
+ - Introduce CLI commands
167
+ - start
168
+ - new
169
+ - Use String literal for hear parameter
170
+ - Chose dsl use in slappy_config
171
+
172
+ - v0.2.0
173
+ - Modify interface
174
+
175
+ - v0.1.0
176
+ - Release
177
+
154
178
  ## Feature
155
179
 
156
180
  - [ ] Execute in shell (because testable).
data/lib/slappy/cli.rb CHANGED
@@ -10,6 +10,11 @@ module Slappy
10
10
  build_command(:generator).call(dir_name)
11
11
  end
12
12
 
13
+ desc 'version', 'show version number'
14
+ def version
15
+ puts Slappy::VERSION
16
+ end
17
+
13
18
  private
14
19
 
15
20
  def build_command(command_name)
@@ -8,6 +8,7 @@ module Slappy
8
8
 
9
9
  mkdir target_dir unless @target_dir.nil?
10
10
  mkdir scripts_dir_path
11
+ mkdir lib_dir_path
11
12
 
12
13
  copy template_script_path, scripts_dir_path
13
14
  copy config_file_path, target_dir
@@ -27,6 +28,10 @@ module Slappy
27
28
  File.expand_path 'templates', gem_root_dir
28
29
  end
29
30
 
31
+ def lib_dir_path
32
+ File.expand_path Slappy.configuration.lib_dir_path, target_dir
33
+ end
34
+
30
35
  def scripts_dir_path
31
36
  File.expand_path Slappy.configuration.scripts_dir_path, target_dir
32
37
  end
@@ -4,7 +4,9 @@ module Slappy
4
4
  class InvalidPathError < StandardError; end
5
5
 
6
6
  def call
7
+ load_dsl
7
8
  load_config
9
+ load_libs
8
10
  load_scripts
9
11
  Slappy.start
10
12
  rescue InvalidPathError => e
@@ -13,6 +15,11 @@ module Slappy
13
15
 
14
16
  private
15
17
 
18
+ def load_dsl
19
+ return if Slappy.configuration.dsl == :disabled
20
+ require 'slappy/dsl'
21
+ end
22
+
16
23
  def load_config
17
24
  file = File.expand_path Slappy.configuration.config_file_path, Dir.pwd
18
25
  begin
@@ -22,18 +29,32 @@ module Slappy
22
29
  end
23
30
  end
24
31
 
25
- def load_scripts
26
- script_dir = Slappy.configuration.scripts_dir_path
32
+ def load_directory(dir_name, &block)
33
+ dir_path = Slappy.configuration.send dir_name.to_sym
27
34
 
28
- unless FileTest.directory? script_dir
29
- message = "directory #{script_dir} not found"
35
+ unless FileTest.directory? dir_path
36
+ message = "directory #{dir_path} not found"
30
37
  fail InvalidPathError.new, message
31
38
  end
32
39
 
33
- script_dir = "./#{script_dir}" unless script_dir.match(%r{"./"})
34
- Dir.glob("#{script_dir}/**/*.rb").each do |file|
35
- block = proc { require file }
36
- block.call
40
+ dir_path = "./#{dir_path}" unless dir_path.match(%r{"./"})
41
+ block.call(dir_path)
42
+ end
43
+
44
+ def load_libs
45
+ load_directory(:lib_dir_path) do |lib_dir|
46
+ Dir.glob("#{lib_dir}/**/*.rb").each do |file|
47
+ require file
48
+ end
49
+ end
50
+ end
51
+
52
+ def load_scripts
53
+ load_directory(:scripts_dir_path) do |script_dir|
54
+ Dir.glob("#{script_dir}/**/*.rb").each do |file|
55
+ block = proc { require file }
56
+ block.call
57
+ end
37
58
  end
38
59
  end
39
60
  end
@@ -1,11 +1,19 @@
1
1
  module Slappy
2
2
  class Configuration
3
- attr_accessor :robot, :token, :scripts_dir_path
3
+ attr_accessor :robot, :token, :scripts_dir_path, :lib_dir_path, :logger
4
4
 
5
5
  def initialize
6
6
  @robot = Robot.new
7
7
  end
8
8
 
9
+ def logger
10
+ unless @logger
11
+ @logger = Logger.new(STDOUT)
12
+ @logger.level = Logger::INFO
13
+ end
14
+ @logger
15
+ end
16
+
9
17
  def token
10
18
  @token || ENV['SLACK_TOKEN']
11
19
  end
@@ -14,10 +22,22 @@ module Slappy
14
22
  './slappy_config.rb'
15
23
  end
16
24
 
25
+ def lib_dir_path
26
+ @lib_dir_path || './lib'
27
+ end
28
+
17
29
  def scripts_dir_path
18
30
  @scripts_dir_path || './slappy-scripts'
19
31
  end
20
32
 
33
+ def dsl
34
+ @dsl || :enabled
35
+ end
36
+
37
+ def dsl=(symbol)
38
+ fail ArgumentError if [:enabled, :disabled].include? symbol
39
+ end
40
+
21
41
  def send_params
22
42
  {
23
43
  username: robot.username,
data/lib/slappy/dsl.rb CHANGED
@@ -2,7 +2,7 @@ module Slappy
2
2
  module DSL
3
3
  extend Forwardable
4
4
 
5
- def_delegators :Slappy, :hello, :hear, :say, :start
5
+ def_delegators :Slappy, :hello, :hear, :say, :start, :logger
6
6
  end
7
7
  end
8
8
 
@@ -7,7 +7,7 @@ module Slappy
7
7
  end
8
8
 
9
9
  def call(event)
10
- return unless Time.at(event.ts.to_f) > Slappy.start_time
10
+ return unless Time.at(event.ts.to_f) > Slappy.client.start_time
11
11
  return unless event.text.match @regexp
12
12
  @callback.call(event)
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module Slappy
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/lib/slappy.rb CHANGED
@@ -4,10 +4,14 @@ require 'hashie'
4
4
  require 'slack'
5
5
  require 'termcolor'
6
6
  require 'thor'
7
+ require 'logger'
7
8
 
8
9
  module Slappy
9
10
  class << self
10
- @configuration = nil
11
+ extend Forwardable
12
+
13
+ def_delegators :configuration, :logger
14
+ def_delegators :client, :start, :hello, :hear, :say
11
15
 
12
16
  def configure
13
17
  @configuration = Configuration.new
@@ -21,17 +25,6 @@ module Slappy
21
25
  @configuration || configure
22
26
  end
23
27
 
24
- def method_missing(method, *args, &block)
25
- return super unless client.respond_to?(method)
26
- client.send(method, *args, &block)
27
- end
28
-
29
- def respond_to?(method)
30
- client.respond_to?(method) || super
31
- end
32
-
33
- private
34
-
35
28
  def client
36
29
  @client ||= Client.new
37
30
  end
@@ -1,16 +1,33 @@
1
- require 'slappy/dsl'
2
-
3
1
  Slappy.configure do |config|
4
2
  ## Slappy Settings
5
3
  #
6
4
  # token:
7
5
  # Slack API Token
8
- config.token = ENV['SLACK_TOKEN']
6
+ #
7
+ # config.token = ENV['SLACK_TOKEN']
9
8
 
10
9
  # scripts_path_dir:
11
10
  # Slappy scripts directory.
12
11
  # Slappy load scripts in this directory.
13
- config.scripts_dir_path = 'slappy-scripts'
12
+ #
13
+ # config.scripts_dir_path = 'slappy-scripts'
14
+
15
+ # logger:
16
+ # Use logger object.
17
+ #
18
+ # config.logger = Logger.new(STDOUT)
19
+
20
+ # logger.level:
21
+ # Specify logger level.
22
+ #
23
+ # config.logger.level = Logger::INFO
24
+
25
+ # dsl:
26
+ # use dsl
27
+ #
28
+ # param: :enabled or :disabled
29
+ #
30
+ # config.dsl = :enabled
14
31
 
15
32
  ## Default parameters
16
33
  #
@@ -23,18 +40,22 @@ Slappy.configure do |config|
23
40
 
24
41
  # username:
25
42
  # Name of bot.
26
- config.robot.username = 'slappy'
43
+ #
44
+ # config.robot.username = 'slappy'
27
45
 
28
46
  # channel:
29
47
  # Channel, private group, or IM channel to send message to.
30
48
  # Can be an encoded ID, or a name. See below for more details.
31
- config.robot.channel = nil
49
+ #
50
+ # config.robot.channel = nil
32
51
 
33
52
  # icon_emoji:
34
53
  # emoji to use as the icon for this message. Overrides icon_url.
35
- config.robot.icon_emoji = nil
54
+ #
55
+ # config.robot.icon_emoji = nil
36
56
 
37
57
  # icon_url:
38
58
  # URL to an image to use as the icon for this message
39
- config.robot.icon_url = nil
59
+ #
60
+ # config.robot.icon_url = nil
40
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slappy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wakaba260
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-08 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-api