rounders 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c20df9444c0ea3a02ae7bce7d0e07fe69cdffe56
4
- data.tar.gz: 799eb26e1694a3973efcc3ffc0bdad6677b1e902
3
+ metadata.gz: 1848b1a79ddcaa6da0ea0ea7504a91e8bc2d627c
4
+ data.tar.gz: 8c7146f3cf50f54d99e4c77a313e61d24849a4f9
5
5
  SHA512:
6
- metadata.gz: ef607ee7317ad8a51c76c4b3cc9dee24adc827c4d1bf6065f065bad938da2718f18f8927006fdc0184d2df43c43512484a6b3406488fe90724d953f25fe96324
7
- data.tar.gz: 0211d80d36d2dda5ac88fca66c5e86f02aa0a0085c4de833ac8bb067f2b0b7cf905401e4533248b15af8b055411c686bf615a9a89907a2f064099a2dda557fd0
6
+ metadata.gz: b063b78cc4418e6cfb8410ae63b71c6d87e362a0552dfbbc39a6d1136185926eafb7d6956bdbeca84ae1dcbb42d00331b0f84887f0f60305c920eaaff5ed0134
7
+ data.tar.gz: 32aef46a039116f55d600022e0c3e6deb875113736d236384ab6a807d785e2f2e90fdebfb95e61713e3cd946e6d2a170c3415ce6639a72875bcb58434f66e128
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rounders [![Circle CI](https://circleci.com/gh/rike422/rounders.svg?style=svg)](https://circleci.com/gh/rike422/rounders) [![Code Climate](https://codeclimate.com/github/rike422/rounders/badges/gpa.svg)](https://codeclimate.com/github/rike422/rounders)
1
+ # Rounders [![Circle CI](https://circleci.com/gh/rike422/rounders.svg?style=svg)](https://circleci.com/gh/rike422/rounders) [![Code Climate](https://codeclimate.com/github/rike422/rounders/badges/gpa.svg)](https://codeclimate.com/github/rike422/rounders) [![Coverage Status](https://coveralls.io/repos/github/rike422/rounders/badge.svg?branch=master)](https://coveralls.io/github/rike422/rounders?branch=master)
2
2
 
3
3
  The pluggalbe mail processing framework
4
4
 
@@ -30,7 +30,7 @@ rounders new [name]
30
30
 
31
31
  ### generator
32
32
 
33
- #### handler
33
+ #### Handlers
34
34
 
35
35
  The `rounders generate handler` command create template of handler into ./plugins/handlers/
36
36
 
@@ -45,18 +45,23 @@ module Rounders
45
45
  class MyHandler < Rounders::Handlers::Handler
46
46
  # mail.body is include 'exmpale'
47
47
  on({ body: 'example' }, :callback_method1)
48
- # body include 'exmpale' AND subject include 'my_subject'
48
+ # body include 'exmpale' AND subject match the /programing (?<name>.+)$/
49
49
  on({
50
50
  body: 'example',
51
- subject: /my_subject/},
51
+ subject: /programing (?<name>.+)$/},
52
52
  :callback_method2)
53
53
 
54
54
  def method1(mail)
55
+ matches[:body]
56
+ # => #<MatchData "example">
55
57
  # any process
56
58
  end
57
59
 
58
60
  def method2(mail)
59
- # any process
61
+ matches[:subject]
62
+ # => <MatchData "programing ruby" name:"ruby">
63
+ matches[:subject][:name]
64
+ # => "ruby"
60
65
  end
61
66
  end
62
67
  end
@@ -64,9 +69,65 @@ end
64
69
 
65
70
  ```
66
71
 
67
- #### matcher
72
+ #### Matchers
68
73
 
69
- coming soon...
74
+ The `rounders generate matchers` command create template of matchers into ./plugins/matchers/
75
+
76
+ ```
77
+ rounders generate matchers [name]`
78
+ ```
79
+
80
+ your writen the matcher plugins that usable some handlers
81
+
82
+ #### exmaple
83
+
84
+ /plugins/matchers/css_selector.rb
85
+
86
+ ```ruby
87
+ module Rounders
88
+ module Matchers
89
+ class CssSelector < Rounders::Matchers::Matcher
90
+ attr_reader :pattern
91
+
92
+ def initialize(pattern)
93
+ @pattern = pattern
94
+ end
95
+
96
+ def match(mail)
97
+ return if mail.html_part.blank?
98
+ html_part = Nokogiri::HTML(mail.html_part.body.to_s)
99
+ node = html_part.css(pattern)
100
+ node.present? ? node : nil
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ ```
107
+
108
+ /plugins/handlers/your_hander.rb
109
+ ```ruby
110
+ module Rounders
111
+ module Handlers
112
+ class YourHandler < Rounders::Handlers::Handler
113
+ # css selector match
114
+ on({ css_selector: 'body .header h2' }, method1)
115
+
116
+ def method1(mail)
117
+ matches[:css_selector]
118
+ # =>[#<Nokogiri::XML::Element:0x3fc6d77f6ccc name="h2" children=[#<Nokogiri::XML::Text:0x3fc6d77f6ad8 " head text ">]>]
119
+ matches[:css_selector].to_s
120
+ # => '<h2> head text </h2>'
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ ```
127
+
128
+ #### Gems
129
+
130
+ - [rounders-css_selector_matcher](https://github.com/rike422/rounders-css_selector_matcher)
70
131
 
71
132
  #### reciever
72
133
 
data/bin/rounders CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
- require 'rubygems'
3
+ require 'bundler/setup'
4
4
  require 'rounders'
5
5
 
6
6
  Rounders::Commander.start(ARGV)
@@ -7,6 +7,11 @@ module Rounders
7
7
  def handler(name, *handlers)
8
8
  Rounders::Generators::Handler.new(name: name, handlers: handlers).generate
9
9
  end
10
+
11
+ desc 'matcher <name> [<handlers>...]', 'Generate new matcher'
12
+ def matcher(name)
13
+ Rounders::Generators::Matcher.new(name: name).generate
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -0,0 +1,9 @@
1
+ module Rounders
2
+ module Generators
3
+ class Matcher < Generator
4
+ def initialize(name: nil)
5
+ super(name)
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/rounders/mail.rb CHANGED
@@ -1,14 +1,52 @@
1
1
  module Rounders
2
2
  class Mail
3
3
  extend Forwardable
4
+ attr_reader :mail
4
5
  def_delegators :@mail,
6
+ :all_parts,
7
+ :attachment,
8
+ :attachment?,
9
+ :attachments,
10
+ :bcc,
5
11
  :body,
12
+ :body_encoding,
6
13
  :cc,
14
+ :charset,
15
+ :comments,
16
+ :content_description,
17
+ :content_id,
18
+ :content_location,
19
+ :content_transfer_encoding,
20
+ :content_type,
21
+ :date,
22
+ :decode_body,
23
+ :decoded,
24
+ :default,
25
+ :encoded,
26
+ :envelope_date,
7
27
  :envelope_from,
28
+ :filename,
8
29
  :from,
9
- :date,
30
+ :has_attachments?,
31
+ :header,
32
+ :headers,
33
+ :html_part,
34
+ :in_reply_to,
35
+ :keywords,
36
+ :main_type,
37
+ :message_content_type,
38
+ :message_id,
39
+ :mime_parameters,
40
+ :mime_type,
41
+ :mime_version,
42
+ :multipart_report?,
43
+ :part,
44
+ :parts,
10
45
  :sender,
46
+ :sub_type,
11
47
  :subject,
48
+ :text?,
49
+ :text_part,
12
50
  :to
13
51
 
14
52
  def initialize(mail)
@@ -12,21 +12,28 @@ module Rounders
12
12
 
13
13
  def match(message)
14
14
  match_data = matchers.each_with_object({}) do |matcher, memo|
15
- memo[matcher.class.name.demodulize.underscore.to_sym] = matcher.match(message)
15
+ memo[matcher.class.symbol] = matcher.match(message)
16
16
  end
17
17
  return match_data if match_data.values.all?(&:present?)
18
18
  nil
19
19
  end
20
20
 
21
21
  class << self
22
+ def inherited(klass)
23
+ Rounders.matchers[klass.symbol] = klass
24
+ end
25
+
26
+ def symbol
27
+ name.demodulize.underscore.to_sym
28
+ end
29
+
22
30
  def build(conditions)
23
31
  matchers = conditions.map do |key, pattern|
24
- matcher = "#{name.deconstantize}::#{key.to_s.classify}".constantize
32
+ matcher = Rounders.matchers[key]
33
+ raise Rounders::Matchers::NoImplementError if matcher.blank?
25
34
  matcher.new(pattern)
26
35
  end
27
36
  new(matchers)
28
- rescue NameError
29
- raise Rounders::Matchers::NoImplementError
30
37
  rescue StandardError => e
31
38
  raise e
32
39
  end
@@ -1,5 +1,6 @@
1
1
  module Rounders
2
2
  class Rounder
3
+ DEFAULT_ENV = 'development'.freeze
3
4
  DEFAULT_INTERVAL = 10
4
5
 
5
6
  def dotenv
@@ -13,6 +14,17 @@ module Rounders
13
14
 
14
15
  private
15
16
 
17
+ def bundle
18
+ ::Bundler.require(:default, env)
19
+ rescue ::Bundler::GemfileNotFound => e
20
+ puts e
21
+ exit
22
+ end
23
+
24
+ def env
25
+ ENV['ROUNDERS_ENV'] || DEFAULT_ENV
26
+ end
27
+
16
28
  def handle(mails)
17
29
  Rounders.handlers.map { |handler| handler.dispatch(self, mails) }
18
30
  end
@@ -39,6 +51,7 @@ module Rounders
39
51
  end
40
52
 
41
53
  def setup
54
+ bundle
42
55
  load_config
43
56
  Rounders::Plugins::PluginLoader.load_plugins
44
57
  end
@@ -1,3 +1,3 @@
1
1
  module Rounders
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/rounders.rb CHANGED
@@ -8,6 +8,10 @@ module Rounders
8
8
  def handlers
9
9
  @handlers ||= []
10
10
  end
11
+
12
+ def matchers
13
+ @matchers ||= {}
14
+ end
11
15
  end
12
16
  end
13
17
 
@@ -36,3 +40,4 @@ require 'rounders/brains/base'
36
40
  require 'rounders/generators/generator'
37
41
  require 'rounders/generators/app'
38
42
  require 'rounders/generators/handler'
43
+ require 'rounders/generators/matcher'
data/rounders.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['akira.takahashi']
10
10
  spec.email = ['rike422@gmail.com']
11
11
 
12
- spec.summary = 'Rounders is Mail processing framework is similar Bot, inspired by ruboty and mailman'
12
+ spec.summary = 'bot-ish pluggable incoming mail processing framework'
13
13
  spec.homepage = 'https://github.com/rike422/rounders'
14
14
  spec.license = 'MIT'
15
15
 
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.0'
24
24
  spec.add_development_dependency 'simplecov'
25
+ spec.add_development_dependency 'coveralls'
25
26
  spec.add_development_dependency 'codeclimate-test-reporter'
26
27
  spec.add_development_dependency 'guard'
27
28
  spec.add_development_dependency 'guard-rspec'
@@ -0,0 +1,8 @@
1
+ module Rounders
2
+ module Matchers
3
+ class {{ class_name }} < Rounders::Matchers::Matcher
4
+ def match(message)
5
+ end
6
+ end
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rounders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.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: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: codeclimate-test-reporter
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +248,7 @@ files:
234
248
  - lib/rounders/generators/app.rb
235
249
  - lib/rounders/generators/generator.rb
236
250
  - lib/rounders/generators/handler.rb
251
+ - lib/rounders/generators/matcher.rb
237
252
  - lib/rounders/handlers/handler.rb
238
253
  - lib/rounders/mail.rb
239
254
  - lib/rounders/matchers/body.rb
@@ -251,6 +266,7 @@ files:
251
266
  - templates/app/Gemfile
252
267
  - templates/app/config/initializers/mail.rb
253
268
  - templates/generators/handler.mustache.rb
269
+ - templates/generators/matcher.mustache.rb
254
270
  homepage: https://github.com/rike422/rounders
255
271
  licenses:
256
272
  - MIT
@@ -274,6 +290,5 @@ rubyforge_project:
274
290
  rubygems_version: 2.5.1
275
291
  signing_key:
276
292
  specification_version: 4
277
- summary: Rounders is Mail processing framework is similar Bot, inspired by ruboty
278
- and mailman
293
+ summary: bot-ish pluggable incoming mail processing framework
279
294
  test_files: []