slappy 0.5.1 → 0.5.2

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: 1b0b9c15815b3cf1132917f497bf462ac226e8ae
4
- data.tar.gz: 6b56d7a4a85eaac4c46e988a6e2e5728058d6658
3
+ metadata.gz: 2cda9ebb75413427151ae533a04d020a9e9db638
4
+ data.tar.gz: 582468f8b8eb1760fceb92b3b26f6dd83aa07957
5
5
  SHA512:
6
- metadata.gz: fcba756785fa377ca2a3e65164edde9a1fea85f7ae66ac45bb5751e1a1fd5cb3372f1350e18702790ae0768d72f83add8bef188955b93e9d306a86f415c9cfe5
7
- data.tar.gz: c27d86356d760e5a7fe3d1ea67b83b58a96758242eb2509d1e9eaf7b2a5703401df30c6b0772c8bb2d804f782c562e3cad7cab781742b5bf9d0b63510d1c5b25
6
+ metadata.gz: 85575d21f7b3e1c04d65f9a685e133eeb941e42e8bdffbe5637690be61c09f7e9995d0cc963f1c63a6db035ee3b55c2d7e98218f209f93432ae0575e1c9cd971
7
+ data.tar.gz: 526f35c3436c164a3df4846a7a3641a5107130b04d8c8f204191c666d9cca1e10de4d6837e9b0dad265bee7eb6a20ac20f458f9e1f3eec9060db13647e83455a
data/README.md CHANGED
@@ -199,6 +199,10 @@ Slappy.start #=> Start WebSocket connection
199
199
 
200
200
  ## Release Note
201
201
 
202
+ - v0.5.2
203
+ - Add debug logging
204
+ - Fix schedule id is not normality
205
+
202
206
  - v0.5.1
203
207
  - Fix monitor event disabled
204
208
 
data/lib/slappy/client.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Slappy
2
2
  class Client
3
+ include Slappy::Debuggable
4
+
3
5
  attr_reader :start_time
4
6
 
5
7
  def initialize
@@ -17,22 +19,26 @@ module Slappy
17
19
  register_event event_name, listeners
18
20
  end
19
21
  set_signal_trap
22
+ Debug.log 'Slappy start'
20
23
  client.start
21
24
  end
22
25
 
23
26
  def hello(&block)
24
27
  @callbacks[:hello] ||= []
25
28
  @callbacks[:hello].push block
29
+ Debug.log "Add hello event(#{@callbacks[:hello].size})"
26
30
  end
27
31
 
28
32
  def hear(pattern, &block)
29
33
  @callbacks[:message] ||= []
30
34
  @callbacks[:message].push Listener::TextListener.new(pattern, block)
35
+ Debug.log "Add here event(#{@callbacks[:message].size}): #{pattern}"
31
36
  end
32
37
 
33
38
  def monitor(type, &block)
34
39
  @callbacks[type.to_sym] ||= []
35
40
  @callbacks[type.to_sym].push Listener::TypeListener.new(type, block)
41
+ Debug.log "Add monitor event(#{@callbacks[type.to_sym].size}): #{type}"
36
42
  end
37
43
 
38
44
  def say(text, options = {})
@@ -40,9 +46,10 @@ module Slappy
40
46
  Messanger.new(options).message
41
47
  end
42
48
 
43
- def schedule(schedule, options = {}, &block)
49
+ def schedule(pattern, options = {}, &block)
44
50
  @schedule ||= Schedule.new
45
- @schedule.register schedule, options, &block
51
+ @schedule.register pattern, options, &block
52
+ Debug.log "Add schedule event(#{@schedule.list.size}): #{pattern}"
46
53
  end
47
54
 
48
55
  private
@@ -0,0 +1,12 @@
1
+ module Slappy
2
+ module Debuggable
3
+ def self.included(klass)
4
+ mod = Module.new do
5
+ define_singleton_method :log do |message|
6
+ Slappy.logger.try(:debug, "[#{klass.name}] #{message}")
7
+ end
8
+ end
9
+ klass.const_set(:Debug, mod)
10
+ end
11
+ end
12
+ end
@@ -2,6 +2,7 @@ module Slappy
2
2
  module Listener
3
3
  module Listenable
4
4
  include ActiveSupport::Concern
5
+ include Slappy::Debuggable
5
6
 
6
7
  attr_reader :pattern
7
8
 
@@ -11,14 +12,26 @@ module Slappy
11
12
  end
12
13
 
13
14
  def call(event)
14
- return unless time_valid?(event)
15
+ Debug.log "Listen event call: #{target_element}:#{event.send(target_element)}"
16
+
17
+ unless time_valid?(event)
18
+ Debug.log 'Event happend in before start time'
19
+ return
20
+ end
15
21
 
16
22
  target = event.send(target_element)
17
- return unless target
23
+ unless target
24
+ Debug.log 'Target is nil'
25
+ return
26
+ end
18
27
 
19
28
  event.matches = target.match pattern
20
- return unless event.matches
29
+ unless event.matches
30
+ Debug.log "Target is not match pattern(#{pattern})"
31
+ return
32
+ end
21
33
 
34
+ Debug.log "Callback event call: #{pattern}"
22
35
  @callback.call(event)
23
36
  end
24
37
 
@@ -2,6 +2,8 @@ require 'securerandom'
2
2
 
3
3
  module Slappy
4
4
  class Schedule
5
+ include Slappy::Debuggable
6
+
5
7
  class OverScheduleError < StandardError; end
6
8
  class InvalidFormatError < StandardError; end
7
9
 
@@ -9,8 +11,15 @@ module Slappy
9
11
 
10
12
  def register(schedule, options = {}, &block)
11
13
  id = options[:id] || generate_id
12
- schedule_list[id] = Thread.new { Chrono::Trigger.new(schedule) { block.call }.run }
13
- Slappy.logger.try(:debug, "Schedule registerd to #{schedule}")
14
+ list[id] = Thread.new do
15
+ time = Chrono::Iterator.new(schedule).next
16
+ Debug.log "Schedule #{id} registerd to #{schedule}, first call to #{time}"
17
+ Chrono::Trigger.new(schedule) do
18
+ block.call
19
+ time = Chrono::Iterator.new(schedule).next
20
+ Debug.log "Schedule #{id} called by #{schedule}, next call to #{time}"
21
+ end.run
22
+ end
14
23
  id
15
24
  end
16
25
 
@@ -19,20 +28,21 @@ module Slappy
19
28
  if registered
20
29
  @schedule_list[id].kill
21
30
  @schedule_list.delete id
31
+ Debug.log "Schedule #{id} deleted"
22
32
  end
23
33
  registered
24
34
  end
25
35
 
26
- private
27
-
28
- def schedule_list
36
+ def list
29
37
  @schedule_list ||= {}
30
38
  end
31
39
 
40
+ private
41
+
32
42
  def generate_id
33
- figure = Math.log10(DEFAULT_MAX_THREAD) + 1
34
- id = format("%0#{figure}d", SecureRandom.random_number(DEFAULT_MAX_THREAD))
35
- id = generate_id if schedule_list.include? id
43
+ digit = Math.log10(DEFAULT_MAX_THREAD).to_i + 1
44
+ id = format("%0#{digit}d", SecureRandom.random_number(DEFAULT_MAX_THREAD))
45
+ id = generate_id if list.include? id
36
46
  id
37
47
  end
38
48
  end
@@ -1,3 +1,3 @@
1
1
  module Slappy
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
data/lib/slappy.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require 'active_support'
2
- require 'active_support/core_ext'
3
- require 'active_support/concern'
4
2
  require 'chrono'
5
3
  require 'forwardable'
6
4
  require 'hashie'
@@ -34,6 +32,7 @@ module Slappy
34
32
  end
35
33
  end
36
34
 
35
+ require 'slappy/concerns/debuggable'
37
36
  require 'slappy/slack_api/concerns/findable'
38
37
  require 'slappy/slack_api/base'
39
38
  require 'slappy/slack_api/channel'
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.5.1
4
+ version: 0.5.2
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-16 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-api
@@ -245,6 +245,7 @@ files:
245
245
  - lib/slappy/client.rb
246
246
  - lib/slappy/commands/generator.rb
247
247
  - lib/slappy/commands/run.rb
248
+ - lib/slappy/concerns/debuggable.rb
248
249
  - lib/slappy/configuration.rb
249
250
  - lib/slappy/configuration/robot.rb
250
251
  - lib/slappy/dsl.rb