activerecord-overflow_signalizer 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ede4a07b9ede07b3890201238b00ca9672ad29b
4
- data.tar.gz: 40f9de6c873f70b82b76ff4b0bcace62d0617f6e
3
+ metadata.gz: c78090d0511bef9b0dde4bd9806e69d46de9dfd7
4
+ data.tar.gz: 80ff96314dcf36dda7275149eff74840ef4653ac
5
5
  SHA512:
6
- metadata.gz: 6454229cc6a4a9c67e5366a02be8dd06c0c8bbd64cb31ea6a0c5e6b221d184253955e52e98399f4eab56ec9f77d26b11359387279425ef66197274b2f4d54133
7
- data.tar.gz: adeab12a104c11059bce4d10a249d667c7a1ff61f0db471dc4862f11b02e57a76dcc557e9f756e9e23636624669a58a67ad7191a2f6e12a0c70b9bff5224d03b
6
+ metadata.gz: 0afb0998fb161bd0f060bd8cc92f8d3e82b9cb73997169b97fe7f4129b15628c8e877af8ffc1dc80c0e51095913dcea52b691e4eb52513bf123eb935e510b17d
7
+ data.tar.gz: e7ed9f015e87d1d0e678bd9d5f070de49d4a8dfd34bee422f8ff0cfb880c5e4a61750132652b8467119910c3b4044a1534637989d76ce6230e403367adf263ff
data/.travis.yml CHANGED
@@ -4,6 +4,11 @@ gemfile:
4
4
  - gemfiles/ar32.gemfile
5
5
  - gemfiles/ar42.gemfile
6
6
  - gemfiles/ar50.gemfile
7
+ - gemfiles/ar51.gemfile
7
8
  rvm:
8
9
  - 2.3.1
10
+ addons:
11
+ postgresql: '9.4'
12
+ before_script:
13
+ - psql -U postgres -c 'CREATE DATABASE overflow_analyzer_test'
9
14
  before_install: gem install bundler -v 1.14.4
data/Appraisals CHANGED
@@ -1,5 +1,9 @@
1
+ appraise 'ar51' do
2
+ gem 'activerecord', '~> 5.1'
3
+ end
4
+
1
5
  appraise 'ar50' do
2
- gem 'activerecord', '~> 5.0'
6
+ gem 'activerecord', '5.0'
3
7
  end
4
8
 
5
9
  appraise 'ar42' do
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # ActiveRecord::OverflowSignalizer
2
+ [![Build Status](https://travis-ci.org/funbox/activerecord-overflow_signalizer.svg?branch=master)](https://travis-ci.org/funbox/activerecord-overflow_signalizer)
2
3
 
3
- One day primary key field will overflow, but if you use this gem, you will know about it before it happened.
4
+ One day primary key field will overflow, but if you use this gem, you will know about it before it happens.
4
5
 
5
6
  ## Installation
6
7
 
@@ -20,17 +21,18 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
23
- Just placed it somewhere in your app:
24
+ Just place it somewhere in your app:
24
25
  ```ruby
25
- ActiveRecord::OverflowSignalizer.new.analyse!
26
+ ActiveRecord::OverflowSignalizer.new.analyse
26
27
  ```
27
28
 
28
- By default it check all models in your application and log if some primary key will overflow soon or overflowed.
29
+ By default it checks all models in your application and logs if some primary key will overflow soon or overflowed.
30
+ Also you can use unsafe method `#analyse!`, so it will raise error.
29
31
 
30
- You can placed it in some job and perform it by [clockwork](https://github.com/adamwiggins/clockwork)
31
- or just run it when app started in separated thread.
32
+ You can place it in some job and perform it by [clockwork](https://github.com/adamwiggins/clockwork)
33
+ or just run it when app starts in a separate thread.
32
34
 
33
- Also you can pass some parameters in initializer:
35
+ Also you can pass some parameters to the initializer:
34
36
 
35
37
  + Specify logger
36
38
  ```ruby
@@ -42,15 +44,15 @@ By default ActiveRecord::Base.logger
42
44
  ```ruby
43
45
  ActiveRecord::OverflowSignalizer.new(models: [ModelName])
44
46
  ```
45
- By default it retrieve all descendants of ActiveRecord::Base
47
+ By default it retrieves all descendants of ActiveRecord::Base
46
48
 
47
- + Specify count of days. Gem start notify you if some primary key will overflow over the next numbers of days.
49
+ + Specify count of days. Gem starts to notify you if some primary key will overflow over the next number of days.
48
50
  ```ruby
49
51
  ActiveRecord::OverflowSignalizer.new(days_count: 360)
50
52
  ```
51
53
  60 days by default
52
54
 
53
- + You can use own signalizer for sending notification to e-mail, slack, hipchat, etc.
55
+ + You can use your own signalizer for notification sending to e-mail, slack, hipchat, etc.
54
56
  ```ruby
55
57
  class MyAwesomeSignalizer
56
58
  def initialize(some_params)
@@ -64,11 +66,11 @@ end
64
66
 
65
67
  ActiveRecord::OverflowSignalizer.new(signalizer: MyAwesomeSignalizer.new(some_params))
66
68
  ```
67
- By default it use only logging
69
+ By default it uses only logging
68
70
 
69
71
  ## Development
70
72
 
71
- For tests you need postgresql connection specified in `spec/database.yml`.
73
+ For tests you need a postgresql connection specified in `spec/database.yml`.
72
74
 
73
75
  ## Contributing
74
76
 
@@ -3,6 +3,8 @@ require 'active_record'
3
3
 
4
4
  module ActiveRecord
5
5
  class OverflowSignalizer
6
+ class Overflow < StandardError; end
7
+
6
8
  class UnsupportedType < StandardError
7
9
  attr_reader :type
8
10
 
@@ -33,11 +35,17 @@ module ActiveRecord
33
35
  pk = model.columns.select { |c| c.name == model.primary_key }.first
34
36
  max = MAX_VALUE.fetch(pk.sql_type) { |type| raise UnsupportedType, type }
35
37
  if overflow_soon?(max, model)
36
- signalize(table, model.last.public_send(pk.name), max)
38
+ raise Overflow, overflow_message(table, model.last.public_send(pk.name), max)
37
39
  end
38
40
  end
39
41
  end
40
42
 
43
+ def analyse
44
+ analyse!
45
+ rescue Overflow => e
46
+ signalize(e.message)
47
+ end
48
+
41
49
  private
42
50
 
43
51
  def overflow_soon?(max, model)
@@ -58,12 +66,15 @@ module ActiveRecord
58
66
  week_records.reduce(:+) / week_records.keep_if { |v| v > 0 }.size
59
67
  end
60
68
 
61
- def signalize(table, current_value, max_value)
69
+ def overflow_message(table, current_value, max_value)
62
70
  if current_value == max_value
63
- msg = "Primary key in table #{table} overflowed! #{current_value} from #{max_value}"
71
+ "Primary key in table #{table} overflowed! #{current_value} from #{max_value}"
64
72
  else
65
- msg = "Primary key in table #{table} will overflow soon! #{current_value} from #{max_value}"
73
+ "Primary key in table #{table} will overflow soon! #{current_value} from #{max_value}"
66
74
  end
75
+ end
76
+
77
+ def signalize(msg)
67
78
  if @logger && @logger.respond_to?(:warn)
68
79
  @logger.warn(msg)
69
80
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  class OverflowSignalizer
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-overflow_signalizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - v.promzelev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2017-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg