redis_code_cov 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +22 -8
- data/lib/generators/redis_code_cov/install/USAGE +2 -0
- data/lib/generators/redis_code_cov/install/install_generator.rb +11 -0
- data/lib/generators/redis_code_cov/install/templates/redis_code_cov.rb +12 -0
- data/lib/redis_code_cov.rb +39 -4
- data/lib/redis_code_cov/version.rb +1 -1
- data/redis_code_cov.gemspec +5 -3
- metadata +41 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bafd4bef8600c1c81dac3d67786651f3a7c18aa
|
4
|
+
data.tar.gz: f178a593a202deecc8a9d55e07a7b987ed8d01af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: def78688ebceb1d918e03fad02cb51fd339cffc6df1c8cafff424b0fcb91f4614cfca08f918e2487ec97c30d718af1510fe75f4c69d997e3a163d29eb6c1437a
|
7
|
+
data.tar.gz: eead1bfd7808e1406f7d365721e34db3a9c2b641f93e78863e6130304890492eb7078c6dc983944cdd3177e7641a3c579080eef7ab1c01bb9ec364536ee21724
|
data/README.md
CHANGED
@@ -6,8 +6,6 @@ This can be a great tool to see which parts of your code are used often and perh
|
|
6
6
|
|
7
7
|
Warning - this is ALPHA quality software, be careful before running it in production. It will increment a Redis counter for EACH method call. Depeneding on your traffic it could slow down your application.
|
8
8
|
|
9
|
-
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/redis_code_cov`. To experiment with that code, run `bin/console` for an interactive prompt.
|
10
|
-
|
11
9
|
## Installation
|
12
10
|
|
13
11
|
Add this line to your application's Gemfile:
|
@@ -26,18 +24,34 @@ Or install it yourself as:
|
|
26
24
|
|
27
25
|
## Usage
|
28
26
|
|
29
|
-
|
27
|
+
After install run `rails g redis_code_cov:install`. Configure the gem in `config/initializers/redis_code_cov.rb`
|
28
|
+
|
29
|
+
In ApplicationController (or another controller) add:
|
30
30
|
```ruby
|
31
|
-
|
32
|
-
REDIS_CODE_COV = Redis::Namespace.new('codecov', redis: redis_conn)
|
31
|
+
include RedisCodeCov::Controller
|
33
32
|
```
|
34
33
|
|
35
|
-
In
|
34
|
+
In ApplicationJob add:
|
36
35
|
```ruby
|
37
|
-
include RedisCodeCov::
|
36
|
+
include RedisCodeCov::Job
|
38
37
|
```
|
39
38
|
|
40
|
-
|
39
|
+
Data will be stored in Redis DB and namespace configured in the initializer.
|
40
|
+
|
41
|
+
TODO:
|
42
|
+
|
43
|
+
write more tests
|
44
|
+
|
45
|
+
Track method calls in:
|
46
|
+
helpers
|
47
|
+
mailers
|
48
|
+
models
|
49
|
+
views
|
50
|
+
|
51
|
+
For other gems:
|
52
|
+
active model serializers
|
53
|
+
draper decorators
|
54
|
+
pundit policies
|
41
55
|
|
42
56
|
## Development
|
43
57
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RedisCodeCov
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
|
6
|
+
def copy_initializer
|
7
|
+
template 'redis_code_cov.rb', 'config/initializers/redis_code_cov.rb'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# => specify host connection here or in environment specific file.
|
2
|
+
# => you can choose NOT to use namespaces or specify different driver (like :hiredis)
|
3
|
+
if Rails.env.test?
|
4
|
+
REDIS_CODE_COV = Redis::Namespace.new(:codecov, redis: MockRedis.new )
|
5
|
+
else
|
6
|
+
redis_conn = Redis.new(host: 'localhost', port: 6379, db: 0)
|
7
|
+
REDIS_CODE_COV = Redis::Namespace.new(:codecov, redis: redis_conn)
|
8
|
+
end
|
9
|
+
|
10
|
+
# => optional exclusion list of which methods NOT to record
|
11
|
+
# => EXCLUDE_REDIS_CODE_COV = ['MyController.index', 'MyModel.method_name']
|
12
|
+
EXCLUDE_REDIS_CODE_COV = []
|
data/lib/redis_code_cov.rb
CHANGED
@@ -3,18 +3,53 @@ require "active_support/concern"
|
|
3
3
|
require "redis"
|
4
4
|
require "redis-namespace"
|
5
5
|
require "readthis"
|
6
|
+
#require "after_do"
|
6
7
|
|
7
8
|
module RedisCodeCov
|
8
9
|
|
10
|
+
# common code for various classes (controller, models, etc)
|
11
|
+
module Base
|
12
|
+
def redis_code_cov key
|
13
|
+
# => increment the counter unless ClassName.method_name is specifically excluded in initializer
|
14
|
+
REDIS_CODE_COV.incr key unless EXCLUDE_REDIS_CODE_COV.include? key
|
15
|
+
rescue Exception => e
|
16
|
+
# => TODO - for now just doing nothing
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# controller specific code
|
9
21
|
module Controller
|
22
|
+
include Base
|
10
23
|
extend ActiveSupport::Concern
|
11
24
|
included do
|
12
|
-
before_action
|
25
|
+
before_action do
|
26
|
+
key = [self.class.name, params[:action]].join('.')
|
27
|
+
redis_code_cov key
|
28
|
+
end
|
13
29
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
# active job code
|
33
|
+
module Job
|
34
|
+
include Base
|
35
|
+
extend ActiveSupport::Concern
|
36
|
+
included do
|
37
|
+
before_perform do |job|
|
38
|
+
# => TODO - figure out how to call it before other methods in the job class
|
39
|
+
key = [self.class.name, 'perform'].join('.')
|
40
|
+
redis_code_cov key
|
41
|
+
end
|
17
42
|
end
|
18
43
|
end
|
19
44
|
|
45
|
+
# # TODO
|
46
|
+
# module View
|
47
|
+
# end
|
48
|
+
# module Model
|
49
|
+
# end
|
50
|
+
# module Helper
|
51
|
+
# end
|
52
|
+
# module Mailer
|
53
|
+
# end
|
54
|
+
|
20
55
|
end
|
data/redis_code_cov.gemspec
CHANGED
@@ -31,11 +31,13 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 1.12"
|
32
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
-
|
35
34
|
# =>
|
36
|
-
spec.
|
35
|
+
spec.add_development_dependency 'mock_redis', '~> 0.17', '>= 0.17.0'
|
36
|
+
# =>
|
37
|
+
spec.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.7'
|
37
38
|
spec.add_runtime_dependency 'redis', '~> 3.3'
|
38
39
|
spec.add_runtime_dependency 'redis-namespace', '~> 1.5'
|
39
|
-
spec.add_runtime_dependency 'readthis'
|
40
|
+
spec.add_runtime_dependency 'readthis', '~> 1.3', '>= 1.3.0'
|
40
41
|
#spec.add_runtime_dependency 'hiredis', '~> 0.6'
|
42
|
+
#spec.add_runtime_dependency 'after_do', '~> 0.4', '>= 0.4.0'
|
41
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis_code_cov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Polyakovsky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,46 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mock_redis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.17'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.17.0
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.17'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.17.0
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: activesupport
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
58
78
|
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.2'
|
59
82
|
- - ">="
|
60
83
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
84
|
+
version: 4.2.7
|
62
85
|
type: :runtime
|
63
86
|
prerelease: false
|
64
87
|
version_requirements: !ruby/object:Gem::Requirement
|
65
88
|
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '4.2'
|
66
92
|
- - ">="
|
67
93
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
94
|
+
version: 4.2.7
|
69
95
|
- !ruby/object:Gem::Dependency
|
70
96
|
name: redis
|
71
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,16 +124,22 @@ dependencies:
|
|
98
124
|
name: readthis
|
99
125
|
requirement: !ruby/object:Gem::Requirement
|
100
126
|
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '1.3'
|
101
130
|
- - ">="
|
102
131
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
132
|
+
version: 1.3.0
|
104
133
|
type: :runtime
|
105
134
|
prerelease: false
|
106
135
|
version_requirements: !ruby/object:Gem::Requirement
|
107
136
|
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '1.3'
|
108
140
|
- - ">="
|
109
141
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
142
|
+
version: 1.3.0
|
111
143
|
description: For every method call in prod it will increment a Redis counter ClassName.method_name. Be
|
112
144
|
careful about performance impact
|
113
145
|
email:
|
@@ -127,6 +159,9 @@ files:
|
|
127
159
|
- Rakefile
|
128
160
|
- bin/console
|
129
161
|
- bin/setup
|
162
|
+
- lib/generators/redis_code_cov/install/USAGE
|
163
|
+
- lib/generators/redis_code_cov/install/install_generator.rb
|
164
|
+
- lib/generators/redis_code_cov/install/templates/redis_code_cov.rb
|
130
165
|
- lib/redis_code_cov.rb
|
131
166
|
- lib/redis_code_cov/version.rb
|
132
167
|
- redis_code_cov.gemspec
|