rounders 0.2.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +10 -1
  5. data/.travis.yml +9 -0
  6. data/README.ja.md +196 -0
  7. data/README.md +56 -8
  8. data/lib/rounders.rb +18 -10
  9. data/lib/rounders/commands/global_command.rb +13 -5
  10. data/lib/rounders/commands/sub_commands/generate.rb +24 -8
  11. data/lib/rounders/generators/app/app_generator.rb +46 -0
  12. data/lib/rounders/generators/app/templates/.rspec +2 -0
  13. data/lib/rounders/generators/app/templates/Gemfile +10 -0
  14. data/lib/rounders/generators/app/templates/MIT-LICENSE +20 -0
  15. data/lib/rounders/generators/app/templates/README.md.tt +21 -0
  16. data/lib/rounders/generators/app/templates/Rakefile +4 -0
  17. data/lib/rounders/generators/app/templates/app/handlers/.gitkeep +0 -0
  18. data/lib/rounders/generators/app/templates/app/matchers/.gitkeep +0 -0
  19. data/lib/rounders/generators/app/templates/app/receivers/.gitkeep +0 -0
  20. data/{templates/app → lib/rounders/generators/app/templates}/config/initializers/mail.rb +2 -2
  21. data/lib/rounders/generators/app/templates/gitignore +54 -0
  22. data/lib/rounders/generators/app/templates/spec/handlers/.gitkeep +0 -0
  23. data/lib/rounders/generators/app/templates/spec/matchers/.gitkeep +0 -0
  24. data/lib/rounders/generators/app/templates/spec/receivers/.gitkeep +0 -0
  25. data/lib/rounders/generators/app/templates/spec/spec_helper.rb.tt +105 -0
  26. data/lib/rounders/generators/app/templates/travis.yml +9 -0
  27. data/lib/rounders/generators/base.rb +69 -0
  28. data/lib/rounders/generators/handler/handler_generator.rb +16 -0
  29. data/lib/rounders/generators/handler/templates/%underscored_name%_handler.rb.tt +12 -0
  30. data/lib/rounders/generators/matcher/matcher_generator.rb +15 -0
  31. data/{templates/generators/matcher.mustache.rb → lib/rounders/generators/matcher/templates/%underscored_name%_matcher.rb.tt} +1 -1
  32. data/lib/rounders/generators/plugin/plugin_generator.rb +49 -0
  33. data/lib/rounders/generators/plugin/templates/.rspec +2 -0
  34. data/lib/rounders/generators/plugin/templates/Gemfile +4 -0
  35. data/lib/rounders/generators/plugin/templates/MIT-LICENSE +20 -0
  36. data/lib/rounders/generators/plugin/templates/README.md.tt +35 -0
  37. data/lib/rounders/generators/plugin/templates/Rakefile +4 -0
  38. data/lib/rounders/generators/plugin/templates/gitignore +54 -0
  39. data/lib/rounders/generators/plugin/templates/lib/rounders/%underscored_name%.rb.tt +6 -0
  40. data/lib/rounders/generators/plugin/templates/lib/rounders/%underscored_name%/version.rb.tt +5 -0
  41. data/lib/rounders/generators/plugin/templates/rounders-%underscored_name%.gemspec.tt +25 -0
  42. data/lib/rounders/generators/plugin/templates/spec/rounders/%underscored_name%_spec.rb.tt +7 -0
  43. data/lib/rounders/generators/plugin/templates/spec/rounders/.gitkeep +0 -0
  44. data/lib/rounders/generators/plugin/templates/spec/spec_helper.rb.tt +123 -0
  45. data/lib/rounders/generators/plugin/templates/travis.yml +9 -0
  46. data/lib/rounders/generators/receiver/receiver_generator.rb +15 -0
  47. data/lib/rounders/generators/receiver/templates/%underscored_name%_receiver.rb.tt +16 -0
  48. data/lib/rounders/handlers/handler.rb +3 -2
  49. data/lib/rounders/matchers/matcher.rb +4 -3
  50. data/lib/rounders/plugins/pluggable.rb +12 -2
  51. data/lib/rounders/receivers/mail.rb +41 -0
  52. data/lib/rounders/receivers/receiver.rb +29 -0
  53. data/lib/rounders/rounder.rb +1 -1
  54. data/lib/rounders/util.rb +20 -0
  55. data/lib/rounders/version.rb +1 -1
  56. data/rounders.gemspec +6 -5
  57. metadata +65 -33
  58. data/circle.yml +0 -36
  59. data/lib/rounders/generators/app.rb +0 -28
  60. data/lib/rounders/generators/generator.rb +0 -48
  61. data/lib/rounders/generators/handler.rb +0 -12
  62. data/lib/rounders/generators/matcher.rb +0 -9
  63. data/lib/rounders/receiver.rb +0 -67
  64. data/templates/app/Gemfile +0 -2
  65. data/templates/generators/handler.mustache.rb +0 -14
@@ -4,6 +4,7 @@ module Rounders
4
4
  end
5
5
  class Matcher
6
6
  include Rounders::Plugins::Pluggable
7
+
7
8
  attr_reader :matchers
8
9
 
9
10
  def initialize(matchers)
@@ -14,7 +15,7 @@ module Rounders
14
15
  match_data = matchers.each_with_object({}) do |matcher, memo|
15
16
  memo[matcher.class.symbol] = matcher.match(message)
16
17
  end
17
- return match_data if match_data.values.all?(&:present?)
18
+ return match_data if match_data.values.none? { |value| Util.blank?(value) }
18
19
  nil
19
20
  end
20
21
 
@@ -24,13 +25,13 @@ module Rounders
24
25
  end
25
26
 
26
27
  def symbol
27
- name.demodulize.underscore.to_sym
28
+ Util.infrect(name.split('::').last).underscore.to_sym
28
29
  end
29
30
 
30
31
  def build(conditions)
31
32
  matchers = conditions.map do |key, pattern|
32
33
  matcher = Rounders.matchers[key]
33
- raise Rounders::Matchers::NoImplementError if matcher.blank?
34
+ raise Rounders::Matchers::NoImplementError if matcher.nil?
34
35
  matcher.new(pattern)
35
36
  end
36
37
  new(matchers)
@@ -10,12 +10,22 @@ module Rounders
10
10
  end
11
11
 
12
12
  module ClassMethods
13
+ def feature_name
14
+ @feature_name ||= begin
15
+ name_spaces = name.to_s.split('::')
16
+ class_name = name_spaces.last
17
+ module_name = Rounders::Util.infrect(name_spaces[-2]).singularize.classify
18
+ class_name.sub!(/#{module_name}$/, '')
19
+ Rounders::Util.infrect(class_name).underscore
20
+ end
21
+ end
22
+
13
23
  def directory_name
14
- @directory_name ||= name.demodulize.downcase.pluralize
24
+ @directory_name ||= Util.infrect(feature_name).pluralize
15
25
  end
16
26
 
17
27
  def load_path
18
- @load_path ||= File.join(Rounders::PLUGIN_DIR_PATH, directory_name)
28
+ @load_path ||= File.join(Rounders::APP_PATH, directory_name)
19
29
  end
20
30
 
21
31
  def load_plugins
@@ -0,0 +1,41 @@
1
+ module Rounders
2
+ module Receivers
3
+ class Mail < Rounders::Receivers::Receiver
4
+ setting :protocol, :imap
5
+ setting :options, {}
6
+ setting :mail_server_setting
7
+ DEFAULT_FIND_OPTION = {
8
+ keys: %w[NOT SEEN]
9
+ }.freeze
10
+
11
+ def initialize(client: nil, options: {})
12
+ @client = client
13
+ @options = DEFAULT_FIND_OPTION.merge(options)
14
+ end
15
+
16
+ def receive
17
+ @client.find(@options).map { |message| Rounders::Mail.new(message) }
18
+ end
19
+
20
+ class << self
21
+ def create
22
+ config = Mail.config
23
+ retriever = parser.lookup_retriever_method(config.protocol)
24
+ new(
25
+ client: retriever.new(config.mail_server_setting),
26
+ options: config.options
27
+ )
28
+ end
29
+
30
+ def receive
31
+ @receiver ||= create
32
+ @receiver.receive
33
+ end
34
+
35
+ def parser
36
+ ::Mail::Configuration.instance
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ module Rounders
2
+ module Receivers
3
+ class Receiver
4
+ class << self
5
+ def create_client(config)
6
+ retriever = parser.lookup_retriever_method(config.protocol)
7
+ new(
8
+ client: retriever.new(config.mail_server_settings),
9
+ find_options: config.find_options
10
+ )
11
+ end
12
+
13
+ def inherited(child_class)
14
+ child_class.include Rounders::Plugins::Pluggable
15
+ child_class.extend Dry::Configurable
16
+ Rounders.receivers << child_class
17
+ end
18
+
19
+ def receive
20
+ Rounders.
21
+ receivers.
22
+ map(&:receive).
23
+ flatten.
24
+ sort_by(&:date)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -47,7 +47,7 @@ module Rounders
47
47
  end
48
48
 
49
49
  def receive_mail
50
- Rounders::Receiver.receive
50
+ Rounders::Receivers::Receiver.receive
51
51
  end
52
52
 
53
53
  def setup
@@ -0,0 +1,20 @@
1
+ require 'hanami/utils/blank'
2
+ require 'hanami/utils/string'
3
+
4
+ module Rounders
5
+ class Util
6
+ class << self
7
+ def infrect(str)
8
+ Hanami::Utils::String.new(str)
9
+ end
10
+
11
+ def blank?(obj)
12
+ Hanami::Utils::Blank.blank?(obj)
13
+ end
14
+
15
+ def present?(obj)
16
+ !blank?(obj)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Rounders
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
data/rounders.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'rounders/version'
@@ -19,18 +20,18 @@ Gem::Specification.new do |spec|
19
20
  spec.require_paths = ['lib']
20
21
 
21
22
  spec.add_development_dependency 'bundler', '~> 1.11'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rake', '~> 11.2'
23
24
  spec.add_development_dependency 'rspec', '~> 3.0'
24
25
  spec.add_development_dependency 'simplecov'
25
26
  spec.add_development_dependency 'coveralls'
26
- spec.add_development_dependency 'codeclimate-test-reporter'
27
27
  spec.add_development_dependency 'guard'
28
28
  spec.add_development_dependency 'guard-rspec'
29
29
  spec.add_development_dependency 'guard-rubocop', '~> 1.2.0'
30
30
  spec.add_development_dependency 'pry'
31
- spec.add_dependency 'activesupport'
32
31
  spec.add_dependency 'dotenv'
33
- spec.add_dependency 'mail', '~> 2.6.3'
34
- spec.add_dependency 'mustache'
32
+ spec.add_dependency 'dry-configurable'
33
+ spec.add_dependency 'mail', '~> 2.6.4'
34
+ spec.add_dependency 'mail-gpg'
35
+ spec.add_dependency 'hanami-utils'
35
36
  spec.add_dependency 'thor'
36
37
  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.2.0
4
+ version: 0.4.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-23 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '11.2'
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: '10.0'
40
+ version: '11.2'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: codeclimate-test-reporter
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
83
  - !ruby/object:Gem::Dependency
98
84
  name: guard
99
85
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +137,7 @@ dependencies:
151
137
  - !ruby/object:Gem::Version
152
138
  version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
- name: activesupport
140
+ name: dotenv
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - ">="
@@ -165,7 +151,7 @@ dependencies:
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
153
  - !ruby/object:Gem::Dependency
168
- name: dotenv
154
+ name: dry-configurable
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
157
  - - ">="
@@ -184,16 +170,30 @@ dependencies:
184
170
  requirements:
185
171
  - - "~>"
186
172
  - !ruby/object:Gem::Version
187
- version: 2.6.3
173
+ version: 2.6.4
188
174
  type: :runtime
189
175
  prerelease: false
190
176
  version_requirements: !ruby/object:Gem::Requirement
191
177
  requirements:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
- version: 2.6.3
180
+ version: 2.6.4
181
+ - !ruby/object:Gem::Dependency
182
+ name: mail-gpg
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: mustache
196
+ name: hanami-utils
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ">="
@@ -231,24 +231,58 @@ files:
231
231
  - ".gitignore"
232
232
  - ".rspec"
233
233
  - ".rubocop.yml"
234
+ - ".travis.yml"
234
235
  - CODE_OF_CONDUCT.md
235
236
  - Gemfile
236
237
  - Guardfile
237
238
  - LICENSE.txt
239
+ - README.ja.md
238
240
  - README.md
239
241
  - Rakefile
240
242
  - bin/rounders
241
- - circle.yml
242
243
  - lib/rounders.rb
243
244
  - lib/rounders/brains/base.rb
244
245
  - lib/rounders/commander.rb
245
246
  - lib/rounders/commands/global_command.rb
246
247
  - lib/rounders/commands/local_command.rb
247
248
  - lib/rounders/commands/sub_commands/generate.rb
248
- - lib/rounders/generators/app.rb
249
- - lib/rounders/generators/generator.rb
250
- - lib/rounders/generators/handler.rb
251
- - lib/rounders/generators/matcher.rb
249
+ - lib/rounders/generators/app/app_generator.rb
250
+ - lib/rounders/generators/app/templates/.rspec
251
+ - lib/rounders/generators/app/templates/Gemfile
252
+ - lib/rounders/generators/app/templates/MIT-LICENSE
253
+ - lib/rounders/generators/app/templates/README.md.tt
254
+ - lib/rounders/generators/app/templates/Rakefile
255
+ - lib/rounders/generators/app/templates/app/handlers/.gitkeep
256
+ - lib/rounders/generators/app/templates/app/matchers/.gitkeep
257
+ - lib/rounders/generators/app/templates/app/receivers/.gitkeep
258
+ - lib/rounders/generators/app/templates/config/initializers/mail.rb
259
+ - lib/rounders/generators/app/templates/gitignore
260
+ - lib/rounders/generators/app/templates/spec/handlers/.gitkeep
261
+ - lib/rounders/generators/app/templates/spec/matchers/.gitkeep
262
+ - lib/rounders/generators/app/templates/spec/receivers/.gitkeep
263
+ - lib/rounders/generators/app/templates/spec/spec_helper.rb.tt
264
+ - lib/rounders/generators/app/templates/travis.yml
265
+ - lib/rounders/generators/base.rb
266
+ - lib/rounders/generators/handler/handler_generator.rb
267
+ - lib/rounders/generators/handler/templates/%underscored_name%_handler.rb.tt
268
+ - lib/rounders/generators/matcher/matcher_generator.rb
269
+ - lib/rounders/generators/matcher/templates/%underscored_name%_matcher.rb.tt
270
+ - lib/rounders/generators/plugin/plugin_generator.rb
271
+ - lib/rounders/generators/plugin/templates/.rspec
272
+ - lib/rounders/generators/plugin/templates/Gemfile
273
+ - lib/rounders/generators/plugin/templates/MIT-LICENSE
274
+ - lib/rounders/generators/plugin/templates/README.md.tt
275
+ - lib/rounders/generators/plugin/templates/Rakefile
276
+ - lib/rounders/generators/plugin/templates/gitignore
277
+ - lib/rounders/generators/plugin/templates/lib/rounders/%underscored_name%.rb.tt
278
+ - lib/rounders/generators/plugin/templates/lib/rounders/%underscored_name%/version.rb.tt
279
+ - lib/rounders/generators/plugin/templates/rounders-%underscored_name%.gemspec.tt
280
+ - lib/rounders/generators/plugin/templates/spec/rounders/%underscored_name%_spec.rb.tt
281
+ - lib/rounders/generators/plugin/templates/spec/rounders/.gitkeep
282
+ - lib/rounders/generators/plugin/templates/spec/spec_helper.rb.tt
283
+ - lib/rounders/generators/plugin/templates/travis.yml
284
+ - lib/rounders/generators/receiver/receiver_generator.rb
285
+ - lib/rounders/generators/receiver/templates/%underscored_name%_receiver.rb.tt
252
286
  - lib/rounders/handlers/handler.rb
253
287
  - lib/rounders/mail.rb
254
288
  - lib/rounders/matchers/body.rb
@@ -259,14 +293,12 @@ files:
259
293
  - lib/rounders/matchers/to.rb
260
294
  - lib/rounders/plugins/pluggable.rb
261
295
  - lib/rounders/plugins/plugin_loader.rb
262
- - lib/rounders/receiver.rb
296
+ - lib/rounders/receivers/mail.rb
297
+ - lib/rounders/receivers/receiver.rb
263
298
  - lib/rounders/rounder.rb
299
+ - lib/rounders/util.rb
264
300
  - lib/rounders/version.rb
265
301
  - rounders.gemspec
266
- - templates/app/Gemfile
267
- - templates/app/config/initializers/mail.rb
268
- - templates/generators/handler.mustache.rb
269
- - templates/generators/matcher.mustache.rb
270
302
  homepage: https://github.com/rike422/rounders
271
303
  licenses:
272
304
  - MIT
data/circle.yml DELETED
@@ -1,36 +0,0 @@
1
- ########################
2
- # Customize the test machine
3
- ########################
4
- machine:
5
-
6
- timezone:
7
- Asia/Tokyo
8
-
9
- # Version of ruby to use
10
- ruby:
11
- version:
12
- 2.3.0
13
-
14
- ########################
15
- # Customize dependencies
16
- ########################
17
- dependencies:
18
- cache_directories:
19
- - "vendor/bundle"
20
- override:
21
- - bundle -j4 --path=vendor/bundle
22
-
23
- ########################
24
- # Customize test commands
25
- ########################
26
- test:
27
- post:
28
- - bundle exec rake
29
-
30
- ########################
31
- # Custom notifications
32
- ########################
33
- notify:
34
- webhooks:
35
- # A list of hashes representing hooks. Only the url field is supported.
36
- - url: https://circleci.com/hooks/circle
@@ -1,28 +0,0 @@
1
- module Rounders
2
- module Generators
3
- class App
4
- attr_reader :name
5
- def initialize(name)
6
- @name = name
7
- end
8
-
9
- def target
10
- @target ||= Pathname(File.join(Dir.pwd, name))
11
- end
12
-
13
- def generate!
14
- if target.exist?
15
- puts "#{name} already exists"
16
- exit
17
- end
18
- target.mkpath
19
- FileUtils.copy_entry(template_path, target)
20
- puts "create #{name}"
21
- end
22
-
23
- def template_path
24
- Pathname('../../../../templates/app').expand_path(__FILE__)
25
- end
26
- end
27
- end
28
- end