rounders 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +3 -3
- data/lib/rounders/commands/local_command.rb +5 -4
- data/lib/rounders/logger.rb +15 -0
- data/lib/rounders/mail.rb +15 -0
- data/lib/rounders/matchers/body.rb +5 -2
- data/lib/rounders/matchers/filename.rb +20 -0
- data/lib/rounders/plugins/pluggable.rb +2 -2
- data/lib/rounders/receivers/mail.rb +1 -1
- data/lib/rounders/rounder.rb +23 -3
- data/lib/rounders/version.rb +1 -1
- data/lib/rounders.rb +16 -8
- data/rounders.gemspec +2 -2
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2752f8f6df411ccdfab763a40e5d70a47b982bf2
|
4
|
+
data.tar.gz: e2bb3706d4475de78b346fb3a2a28f31e2ab5200
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e32a9c7aedd35edc6ff2ff06659ee73dd9cf9d2e03664679fc47ccb4b93e48ed26e9714b39784b96cc071b2afe6e9aeb806ef30a6a9225c3f06be1e09cb6d09
|
7
|
+
data.tar.gz: 3c8400e29ca690eebfaabe32d2d036946a0efaebd6adc05409d4f4acad86833aa0835a3670b0f53f1b1d9c7161c8d0100c30d396b61be4797256d34e11a8c30b
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -5,11 +5,12 @@ module Rounders
|
|
5
5
|
package_name 'rounders'
|
6
6
|
|
7
7
|
desc 'start', 'Start the Rounders'
|
8
|
-
|
9
|
-
|
8
|
+
option aliases: '-s'
|
9
|
+
method_option :dotenv, type: :boolean, default: false
|
10
|
+
method_option :daemon, type: :boolean, default: false
|
11
|
+
method_option :pid, type: :string
|
10
12
|
def start
|
11
|
-
rounder = Rounders::Rounder.new
|
12
|
-
rounder.dotenv if options[:dotenv]
|
13
|
+
rounder = Rounders::Rounder.new(options)
|
13
14
|
rounder.start
|
14
15
|
end
|
15
16
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Rounders
|
4
|
+
module Logger
|
5
|
+
class << self
|
6
|
+
def get_logger(level = :info, formatter = nil, io: STDERR)
|
7
|
+
logger = ::Logger.new(io)
|
8
|
+
logger.progname = 'rounders'
|
9
|
+
logger.level = level || :info
|
10
|
+
logger.formatter = formatter if formatter
|
11
|
+
logger
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/rounders/mail.rb
CHANGED
@@ -39,6 +39,7 @@ module Rounders
|
|
39
39
|
:mime_parameters,
|
40
40
|
:mime_type,
|
41
41
|
:mime_version,
|
42
|
+
:multipart?,
|
42
43
|
:multipart_report?,
|
43
44
|
:part,
|
44
45
|
:parts,
|
@@ -52,5 +53,19 @@ module Rounders
|
|
52
53
|
def initialize(mail)
|
53
54
|
@mail = mail
|
54
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def respond_to_missing?(method, *args, &block)
|
60
|
+
mail.respond_to?(method, *args, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
def method_missing(method, *args, &block)
|
64
|
+
if mail.respond_to?(method)
|
65
|
+
mail.public_send(method, *args, &block)
|
66
|
+
else
|
67
|
+
super
|
68
|
+
end
|
69
|
+
end
|
55
70
|
end
|
56
71
|
end
|
@@ -8,8 +8,11 @@ module Rounders
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def match(mail)
|
11
|
-
|
12
|
-
|
11
|
+
if mail.multipart?
|
12
|
+
mail.text_part.decoded.match(pattern)
|
13
|
+
else
|
14
|
+
mail.decoded.match(pattern)
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rounders
|
2
|
+
module Matchers
|
3
|
+
class Filename < Rounders::Matchers::Matcher
|
4
|
+
attr_reader :pattern
|
5
|
+
|
6
|
+
def initialize(pattern)
|
7
|
+
@pattern = pattern
|
8
|
+
end
|
9
|
+
|
10
|
+
def match(message)
|
11
|
+
return if message.attachment?
|
12
|
+
matches = message.attachments.map do |attachment|
|
13
|
+
match = attachment.filename.match(pattern)
|
14
|
+
match.nil? ? nil : attachment
|
15
|
+
end
|
16
|
+
matches.compact
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -29,10 +29,10 @@ module Rounders
|
|
29
29
|
def load_plugins
|
30
30
|
Pathname.glob("#{load_path}/*.rb").each do |plugin|
|
31
31
|
begin
|
32
|
-
|
32
|
+
Rounders.logger.info "load #{plugin.expand_path}"
|
33
33
|
require_relative plugin.expand_path
|
34
34
|
rescue => e
|
35
|
-
|
35
|
+
Rounders.logger.error e
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/rounders/rounder.rb
CHANGED
@@ -3,8 +3,10 @@ module Rounders
|
|
3
3
|
DEFAULT_ENV = 'development'.freeze
|
4
4
|
DEFAULT_INTERVAL = 10
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
8
10
|
end
|
9
11
|
|
10
12
|
def start
|
@@ -17,10 +19,18 @@ module Rounders
|
|
17
19
|
def bundle
|
18
20
|
::Bundler.require(:default, env)
|
19
21
|
rescue ::Bundler::GemfileNotFound => e
|
20
|
-
|
22
|
+
Rounders.logger.error e
|
21
23
|
exit
|
22
24
|
end
|
23
25
|
|
26
|
+
def daemon
|
27
|
+
Process.daemon(true, false) if options[:daemon]
|
28
|
+
end
|
29
|
+
|
30
|
+
def dotenv
|
31
|
+
Dotenv.load if options[:dotenv]
|
32
|
+
end
|
33
|
+
|
24
34
|
def env
|
25
35
|
ENV['ROUNDERS_ENV'] || DEFAULT_ENV
|
26
36
|
end
|
@@ -42,6 +52,13 @@ module Rounders
|
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
55
|
+
def pid
|
56
|
+
path = options[:pid]
|
57
|
+
return if path.nil?
|
58
|
+
File.open(path, 'w') { |f| f.write(Process.pid) }
|
59
|
+
at_exit { File.unlink(path) }
|
60
|
+
end
|
61
|
+
|
45
62
|
def round
|
46
63
|
handle receive_mail
|
47
64
|
end
|
@@ -51,6 +68,9 @@ module Rounders
|
|
51
68
|
end
|
52
69
|
|
53
70
|
def setup
|
71
|
+
daemon
|
72
|
+
dotenv
|
73
|
+
pid
|
54
74
|
bundle
|
55
75
|
load_config
|
56
76
|
Rounders::Plugins::PluginLoader.load_plugins
|
data/lib/rounders/version.rb
CHANGED
data/lib/rounders.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
require 'rounders/version'
|
2
2
|
|
3
|
+
require 'thor'
|
4
|
+
require 'thor/group'
|
5
|
+
require 'dry-configurable'
|
6
|
+
require 'forwardable'
|
7
|
+
require 'mail'
|
8
|
+
require 'dotenv'
|
9
|
+
|
10
|
+
require 'rounders/logger'
|
11
|
+
require 'rounders/util'
|
12
|
+
|
3
13
|
module Rounders
|
4
14
|
# Your code goes here...
|
5
15
|
CONFIG_DIR_PATH = File.join(Dir.pwd, 'config').freeze
|
6
16
|
APP_PATH = File.join(Dir.pwd, 'app').freeze
|
17
|
+
|
7
18
|
class << self
|
19
|
+
attr_accessor :logger
|
20
|
+
|
8
21
|
def handlers
|
9
22
|
@_handlers ||= []
|
10
23
|
end
|
@@ -21,16 +34,10 @@ module Rounders
|
|
21
34
|
!Pathname(Rounders::APP_PATH).exist?
|
22
35
|
end
|
23
36
|
end
|
24
|
-
end
|
25
37
|
|
26
|
-
|
27
|
-
|
28
|
-
require 'dry-configurable'
|
29
|
-
require 'forwardable'
|
30
|
-
require 'mail'
|
31
|
-
require 'dotenv'
|
38
|
+
self.logger = Logger.get_logger
|
39
|
+
end
|
32
40
|
|
33
|
-
require 'rounders/util'
|
34
41
|
require 'rounders/mail'
|
35
42
|
require 'rounders/plugins/plugin_loader'
|
36
43
|
require 'rounders/plugins/pluggable'
|
@@ -39,6 +46,7 @@ require 'rounders/matchers/subject'
|
|
39
46
|
require 'rounders/matchers/body'
|
40
47
|
require 'rounders/matchers/cc'
|
41
48
|
require 'rounders/matchers/from'
|
49
|
+
require 'rounders/matchers/filename'
|
42
50
|
require 'rounders/matchers/to'
|
43
51
|
require 'rounders/handlers/handler'
|
44
52
|
require 'rounders/commander'
|
data/rounders.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_development_dependency 'bundler'
|
23
|
-
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'bundler'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
25
|
spec.add_development_dependency 'simplecov'
|
26
26
|
spec.add_development_dependency 'coveralls'
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rounders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akira.takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -287,9 +287,11 @@ files:
|
|
287
287
|
- lib/rounders/generators/receiver/receiver_generator.rb
|
288
288
|
- lib/rounders/generators/receiver/templates/%underscored_name%_receiver.rb.tt
|
289
289
|
- lib/rounders/handlers/handler.rb
|
290
|
+
- lib/rounders/logger.rb
|
290
291
|
- lib/rounders/mail.rb
|
291
292
|
- lib/rounders/matchers/body.rb
|
292
293
|
- lib/rounders/matchers/cc.rb
|
294
|
+
- lib/rounders/matchers/filename.rb
|
293
295
|
- lib/rounders/matchers/from.rb
|
294
296
|
- lib/rounders/matchers/matcher.rb
|
295
297
|
- lib/rounders/matchers/subject.rb
|