doctor_doug 0.1.1 → 0.1.2

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: f00066984dbab4c4ae5d85e5be6674e3aeaf0cc5
4
- data.tar.gz: 7bcd7d99b698a517e7ae8d4dba8c7278131f0b7b
3
+ metadata.gz: 42cf84aa1d3cbf3284ca1f61cb7a3754f1efcc9a
4
+ data.tar.gz: '002287f99d8c70417f2d64a96b4b68fb05a1b8b9'
5
5
  SHA512:
6
- metadata.gz: 04b9be8641b37b1258f586fbf35849ad57df2ad930f307057e1c30474dcc91d47a9299289eaa1fc3de8452e90d1a72525a1cee754cde1725f907f1ae6adacc75
7
- data.tar.gz: c86934167717183b51fe1a5743eb7121fc9713fc34ee16a51069e2fb3adbf0f9192862f29a48826a04b2ebe5fe7f098ca7b6ce5ac6b7cbe0abba7513ce9148dc
6
+ metadata.gz: 948e853a0f0635426c4ac0cd7727963fa17558cbf8cf53df38e300950f7151d72eb10a08fa73fad0b62ba923ee99463f666b4d34ea8ba3288e242f9e3ceb704e
7
+ data.tar.gz: c019d8343b714f4071f478ab63bf49a048267d4bb21d025655b709a7253a39cda7b1e21530dfe77d22d449f6a313508870632e49898010a80821e9565ed228e7
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ .idea
10
+ coverage
11
+ .DS_Store
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Style/SymbolArray:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Gemspec/OrderedDependencies:
8
+ Enabled: false
9
+
10
+ Layout/IndentHash:
11
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.1
data/Gemfile.lock CHANGED
@@ -1,13 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doctor_doug (0.1.1)
4
+ doctor_doug (0.1.2)
5
+ mail
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ docile (1.3.0)
11
+ json (2.1.0)
12
+ mail (2.7.0)
13
+ mini_mime (>= 0.1.1)
14
+ mini_mime (1.0.0)
9
15
  minitest (5.11.3)
10
16
  rake (10.5.0)
17
+ simplecov (0.16.1)
18
+ docile (~> 1.1)
19
+ json (>= 1.8, < 3)
20
+ simplecov-html (~> 0.10.0)
21
+ simplecov-html (0.10.2)
11
22
 
12
23
  PLATFORMS
13
24
  ruby
@@ -17,6 +28,7 @@ DEPENDENCIES
17
28
  doctor_doug!
18
29
  minitest (~> 5.0)
19
30
  rake (~> 10.0)
31
+ simplecov
20
32
 
21
33
  BUNDLED WITH
22
34
  1.16.1
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # DoctorDoug
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/doctor_doug`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Run checkup and notify you by mail when there are violations
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,33 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```
24
+ # config/initializers/doctor_doug.rb
25
+
26
+ DoctorDoug.configure do |config|
27
+ config.strategies = [:mail]
28
+ config.mail_options = {
29
+ address: 'smtp.gmail.com',
30
+ port: 587,
31
+ domain: 'gmail.com',
32
+ user_name: 'youremail@gmail.com',
33
+ password: 'password',
34
+ authentication: 'plain',
35
+ from: 'from@gmail.com',
36
+ to: 'to@gmail.com'
37
+ }
38
+ end
39
+ ```
40
+
41
+ ```
42
+ DoctorDoug.checkup "user name should not be blank" do
43
+ users = User.where(updated_at: 1.hour.ago..Time.now)
44
+ notify :if, any: users do |user|
45
+ user.name.blank? # to make this work, the block must reutrn a boolean value
46
+ end
47
+ end
48
+
49
+ ```
26
50
 
27
51
  ## Development
28
52
 
@@ -32,4 +56,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
56
 
33
57
  ## Contributing
34
58
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/doctor_doug.
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gaotongfei/doctor_doug.
data/doctor_doug.gemspec CHANGED
@@ -1,35 +1,38 @@
1
1
 
2
- lib = File.expand_path("../lib", __FILE__)
2
+ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "doctor_doug/version"
4
+ require 'doctor_doug/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "doctor_doug"
7
+ spec.name = 'doctor_doug'
8
8
  spec.version = DoctorDoug::VERSION
9
- spec.authors = ["Tongfei Gao"]
10
- spec.email = ["gaotongfei1995@gmail.com"]
9
+ spec.authors = ['Tongfei Gao']
10
+ spec.email = ['gaotongfei1995@gmail.com']
11
11
 
12
12
  spec.summary = %q{Checkups}
13
13
  spec.description = %q{Checks}
14
- spec.homepage = "https://github.com/gaotongfei/doctor_doug"
14
+ spec.homepage = 'https://github.com/gaotongfei/doctor_doug'
15
15
 
16
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
18
18
  if spec.respond_to?(:metadata)
19
19
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
20
  else
21
- raise "RubyGems 2.0 or newer is required to protect against " \
22
- "public gem pushes."
21
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
22
+ 'public gem pushes.'
23
23
  end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
26
  f.match(%r{^(test|spec|features)/})
27
27
  end
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
- spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_dependency 'mail'
33
+
34
+ spec.add_development_dependency 'bundler', '~> 1.16'
35
+ spec.add_development_dependency 'simplecov'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'minitest', '~> 5.0'
35
38
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoctorDoug # :nodoc:
4
+ def self.checkup(name, &block)
5
+ checkup_proxy = CheckupProxy.new(name)
6
+ checkup_proxy.instance_eval(&block)
7
+ end
8
+
9
+ end
10
+
11
+ class CheckupProxy # :nodoc:
12
+ def initialize(checkup_name)
13
+ @checkup_name = checkup_name
14
+ end
15
+
16
+ def notify(condition, any:)
17
+ raise NoneBlockGivenError unless block_given?
18
+ collections = any
19
+ violations = collections.map do |c|
20
+ need_notify = false
21
+ block_result = yield c
22
+ if !!block_result == block_result
23
+ need_notify = block_result if condition == :if
24
+ need_notify = !block_result if condition == :unless
25
+ end
26
+ c if need_notify
27
+ end
28
+
29
+ DoctorDoug::Notify.perform(checkup_name, violations)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :checkup_name
35
+
36
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoctorDoug
4
+ # Configure doctor_doug using block style
5
+ #
6
+ # For example:
7
+ #
8
+ # # config/initializers/doctor_doug.rb
9
+ # DoctorDoug.configure do |config|
10
+ # config.strategies = [:mail]
11
+ # config.mail_options = {
12
+ # address: "smtp.gmail.com",
13
+ # port: 587,
14
+ # domain: 'gmail.com',
15
+ # user_name: 'youremail@gmail.com',
16
+ # password: 'password',
17
+ # authentication: 'plain',
18
+ # from: 'from@gmail.com',
19
+ # to: 'to@gmail.com'
20
+ # }
21
+ # end
22
+ class << self
23
+ attr_accessor :configuration
24
+ end
25
+
26
+ def self.configure
27
+ self.configuration ||= Configuration.new
28
+ yield(configuration)
29
+ end
30
+
31
+ class Configuration # :nodoc:
32
+ attr_accessor :strategies, :mail_options
33
+
34
+ def initialize
35
+ @strategies = [:mail]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NoneBlockGivenError < StandardError # :nodoc:
4
+ def message
5
+ 'None block is given'
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DoctorDoug
4
+ module Notify # :nodoc:
5
+ def self.perform(checkup_name, violations)
6
+ unless violations.empty?
7
+ strategies = DoctorDoug.configuration.strategies
8
+ strategies = valid_strategies(strategies)
9
+ strategies.each do |strategy|
10
+ if strategy == :mail
11
+ DoctorDoug::Notify::Mail.new(DoctorDoug.configuration, violations: violations).deliver(checkup_name: checkup_name)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ class << self
18
+ def valid_strategies(strategies)
19
+ [:mail] & strategies
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module DoctorDoug
26
+ module Notify
27
+ class Base # :nodoc:
28
+ def initialize(violations)
29
+ @violations = violations
30
+ end
31
+
32
+ def message
33
+ "#{@violations.inspect}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mail'
4
+
5
+ module DoctorDoug
6
+ module Notify
7
+ class Mail < Base # :nodoc:
8
+ def initialize(configuration, violations:)
9
+ super(violations)
10
+ @configuration = configuration
11
+
12
+ ::Mail.defaults do
13
+ delivery_method :smtp, configuration.mail_options.slice(:address, :port, :domain, :user_name,
14
+ :password, :authentication)
15
+ end
16
+ end
17
+
18
+ def deliver(checkup_name:)
19
+ configuration = @configuration
20
+ message = self.message
21
+ mail = ::Mail.new do
22
+ from configuration.mail_options[:from]
23
+ to configuration.mail_options[:to]
24
+ subject "Checkup: #{checkup_name} failed"
25
+ body message
26
+ end
27
+ mail.deliver!
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module DoctorDoug
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/doctor_doug.rb CHANGED
@@ -1,5 +1,13 @@
1
- require "doctor_doug/version"
1
+ # frozen_string_literal: true
2
2
 
3
- module DoctorDoug
4
- # Your code goes here...
3
+ require 'doctor_doug/version'
4
+ require 'doctor_doug/checkup'
5
+ require 'doctor_doug/errors'
6
+ require 'doctor_doug/configuration'
7
+ require 'doctor_doug/notify/base'
8
+ require 'doctor_doug/notify/mail'
9
+
10
+ require 'mail'
11
+
12
+ module DoctorDoug # :nodoc:
5
13
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doctor_doug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tongfei Gao
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mail
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +88,8 @@ extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".ruby-version"
63
93
  - ".travis.yml"
64
94
  - Gemfile
65
95
  - Gemfile.lock
@@ -69,6 +99,11 @@ files:
69
99
  - bin/setup
70
100
  - doctor_doug.gemspec
71
101
  - lib/doctor_doug.rb
102
+ - lib/doctor_doug/checkup.rb
103
+ - lib/doctor_doug/configuration.rb
104
+ - lib/doctor_doug/errors.rb
105
+ - lib/doctor_doug/notify/base.rb
106
+ - lib/doctor_doug/notify/mail.rb
72
107
  - lib/doctor_doug/version.rb
73
108
  homepage: https://github.com/gaotongfei/doctor_doug
74
109
  licenses: []