lita-schedule 0.0.1

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: 3c5945ba5b7ad83406ac05b7b2c6caad6f9ea44b
4
+ data.tar.gz: 7b21787e4bf0a19a7d0510a5f9072c7fe078b15f
5
+ SHA512:
6
+ metadata.gz: f3ef88cfa7be18997a97976eb40fa798313b30dc124e2a217715709b5ca984243fbd8831bfdcfeab91d059f8e661574ac68b104ad46b89f7b32c5b8348f229b0
7
+ data.tar.gz: 530ade7f71b3a93a87d17fb5ddcfd31472e34b34d8b99aaf71449ef127321062507d9be144a50a2ec94e337c2f4e563497e81e0a5c4c5f0c524cbb2f822620e6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lita-schedule.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 fukayatsu
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,48 @@
1
+ # Lita::Schedule
2
+
3
+ Add base class for scheduled job (cron) to Lita
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'lita-schedule'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install lita-schedule
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ require 'lita-schedule'
23
+
24
+ module Lita
25
+ module Schedules
26
+ class TimeTone < Lita::Schedule
27
+
28
+ cron('* * * * * Asia/Tokyo', :every_minutes_job)
29
+ def every_minutes_job
30
+ target = Struct.new(:room_jid).new('your_room@conf.hipchat.com')
31
+ robot.send_message(target, Time.now.to_s)
32
+ end
33
+ end
34
+ Lita.register_schedule(TimeTone)
35
+ end
36
+ end
37
+ ```
38
+
39
+ cron-fields comes from [jmettraux/rufus-scheduler](https://github.com/jmettraux/rufus-scheduler)
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require 'lita/lita'
2
+ require 'lita/schedule'
data/lib/lita/lita.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'rufus/scheduler'
2
+
3
+ module Lita
4
+ class << self
5
+ def schedules
6
+ @schedules ||= Set.new
7
+ end
8
+
9
+ def register_schedule(schedule)
10
+ schedules << schedule
11
+ end
12
+ end
13
+
14
+ module ScheduleRobot
15
+ def initialize
16
+ @scheduler = Rufus::Scheduler.start_new
17
+ super
18
+ end
19
+
20
+ def register_schedules
21
+ # @scheduler.every '5s' do
22
+ # puts "hogehoge"
23
+ # end
24
+ Lita.schedules.each { |schedule|
25
+ schedule.jobs.each { |job|
26
+ @scheduler.cron job.cron_field do
27
+ schedule.new(self).send job.job_name
28
+ end
29
+ }
30
+ }
31
+ end
32
+
33
+ def run
34
+ register_schedules
35
+ super
36
+ end
37
+ end
38
+
39
+ class Robot
40
+ prepend ScheduleRobot
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ require "lita/schedule/version"
2
+
3
+ module Lita
4
+ class Schedule
5
+ extend Forwardable
6
+
7
+ attr_reader :redis
8
+ attr_reader :robot
9
+
10
+ Job = Struct.new('Job', :cron_field, :job_name)
11
+
12
+ class << self
13
+ def cron(cron_field, job_name)
14
+ jobs << Job.new(cron_field, job_name)
15
+ end
16
+
17
+ def jobs
18
+ @jobs ||= []
19
+ end
20
+ end
21
+
22
+ def initialize(robot)
23
+ @robot = robot
24
+ @redis = Redis::Namespace.new(Lita::REDIS_NAMESPACE, redis: Lita.redis)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Lita
2
+ class Schedule
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -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 'lita/schedule/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lita-schedule"
8
+ spec.version = Lita::Schedule::VERSION
9
+ spec.authors = ["fukayatsu"]
10
+ spec.email = ["fukayatsu@gmail.com"]
11
+ spec.description = %q{Add base class for scheduled job(cron) to Lita}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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 "lita", "~> 2.2"
22
+ spec.add_runtime_dependency "rufus-scheduler", "~> 2.0.23"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 2.14"
27
+ spec.add_development_dependency "simplecov"
28
+ spec.add_development_dependency "coveralls"
29
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-schedule
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fukayatsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rufus-scheduler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.23
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.23
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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.14'
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
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: coveralls
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
+ description: Add base class for scheduled job(cron) to Lita
112
+ email:
113
+ - fukayatsu@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/lita-schedule.rb
124
+ - lib/lita/lita.rb
125
+ - lib/lita/schedule.rb
126
+ - lib/lita/schedule/version.rb
127
+ - lita-schedule.gemspec
128
+ homepage: ''
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.0.2
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Add base class for scheduled job(cron) to Lita
152
+ test_files: []