arca 2.1.2 → 2.1.3
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/.gitignore +1 -0
- data/.travis.yml +10 -0
- data/README.md +55 -5
- data/arca.gemspec +2 -2
- data/gemfiles/Gemfile_activerecord-3.2 +5 -0
- data/gemfiles/Gemfile_activerecord-4.2 +5 -0
- data/lib/arca/callback_analysis.rb +1 -1
- data/lib/arca/model.rb +1 -4
- data/test/lib/arca/callback_analysis_test.rb +21 -30
- data/test/test_helper.rb +4 -1
- metadata +6 -3
- data/Gemfile.lock +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1becb49c860d2d307b0a29e91a2d93e0bfe86845
|
4
|
+
data.tar.gz: b230fe2a8c7d72fc0d84767de6546d67ea707426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc86642a2abba3e45f437b4607ab54e775a009ea35611202907a3af1d7da8a59fc0fadc110467a5c66ce080f6133e9e409071c50c34254d1fa4d2611392f3777
|
7
|
+
data.tar.gz: bd855300d7bc35f2d5029ec4749cf72572f626a675402f4af92d759b81bb5821cf8b3fca86b1675fa59cb3cfd6afc8d38e52a192a68031a11096867e160094b2
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,12 +1,20 @@
|
|
1
1
|
# ActiveRecord Callback Analyzer
|
2
2
|
|
3
|
-
Arca is a callback analyzer for ActiveRecord
|
3
|
+
Arca is a callback analyzer for ActiveRecord models ideally suited for digging yourself out of callback hell. At best it will help you move towards a [more maintainable design](http://adequate.io/culling-the-activerecord-lifecycle) and at worst it can be used in your test suite to give you feedback when callbacks change.
|
4
|
+
|
5
|
+
Arca helps you answer questions like:
|
4
6
|
|
5
7
|
* how spread out callbacks are for each model
|
6
|
-
* how many callbacks use conditionals (`:if
|
8
|
+
* how many callbacks use conditionals (`:if`, `:unless`, and `:on`)
|
7
9
|
* how many possible permutations exist per callback type (`:commit`, `:create`, `:destroy`, `:find`, `:initialize`, `:rollback`, `:save`, `:touch`, `:update`, `:validation`) taking conditionals into consideration
|
8
10
|
|
9
|
-
The Arca library has two main components, the collector and the reporter. Include the collector module in
|
11
|
+
The Arca library has two main components, the collector and the reporter. Include the collector module in ActiveRecord::Base before your models are loaded.
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
|
15
|
+

|
16
|
+
|
17
|
+
Arca is tested against ActiveRecord 3.2 and 4.2 running on Ruby 1.9.3, 2.0.0, 2.1.0, and 2.2.0.
|
10
18
|
|
11
19
|
## Usage
|
12
20
|
|
@@ -19,11 +27,14 @@ gem 'arca'
|
|
19
27
|
In your test helper (`test/test_helper.rb` for example) require the Arca library and include the `Arca::Collector` in `ActiveRecord::Base`.
|
20
28
|
|
21
29
|
```
|
30
|
+
require "active_record"
|
22
31
|
require "arca"
|
23
32
|
|
24
33
|
class ActiveRecord::Base
|
25
34
|
include Arca::Collector
|
26
35
|
end
|
36
|
+
|
37
|
+
# load your app
|
27
38
|
```
|
28
39
|
|
29
40
|
In this example the `Annoucements` module is included in `Ticket` and defines it's own callback.
|
@@ -71,8 +82,6 @@ end
|
|
71
82
|
Use `Arca[Ticket].report` to analyze the callbacks for the `Ticket` class.
|
72
83
|
|
73
84
|
```ruby
|
74
|
-
> Arca.root_path = `pwd`.chomp
|
75
|
-
=> "/Users/jonmagic/Projects/arca"
|
76
85
|
> Arca[Ticket].report
|
77
86
|
{
|
78
87
|
:model_name => "Ticket",
|
@@ -85,6 +94,11 @@ Use `Arca[Ticket].report` to analyze the callbacks for the `Ticket` class.
|
|
85
94
|
:external_conditionals_count => 0,
|
86
95
|
:calculated_permutations => 2
|
87
96
|
}
|
97
|
+
```
|
98
|
+
|
99
|
+
Try out `Arca[Ticket].analyzed_callbacks` to see where and how each callback works and the order they run in.
|
100
|
+
|
101
|
+
```ruby
|
88
102
|
> Arca[Ticket].analyzed_callbacks
|
89
103
|
{
|
90
104
|
:before_save => [
|
@@ -162,6 +176,42 @@ Use `Arca[Ticket].report` to analyze the callbacks for the `Ticket` class.
|
|
162
176
|
}
|
163
177
|
```
|
164
178
|
|
179
|
+
I'm working [on a project](https://help.github.com/enterprise/2.3/admin/guides/migrations/) at [GitHub](https://github.com) that feels pain when callback behavior changes so I decided to build this tool to help us manage change better and hopefully in the long run move away from ActiveRecord callbacks for most things.
|
180
|
+
|
181
|
+
For the first iteration I am hoping to use this tool in a set of model lint tests that break when callback behavior changes.
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
def assert_equal(expected, actual)
|
185
|
+
super(expected, actual, ARCA_FAILURE_MESSAGE)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_foo
|
189
|
+
report = Arca[Foo].report
|
190
|
+
expected = {
|
191
|
+
:model_name => "Foo",
|
192
|
+
:model_file_path => "app/models/foo.rb",
|
193
|
+
:callbacks_count => 30,
|
194
|
+
:conditionals_count => 3,
|
195
|
+
:lines_between_count => 1026,
|
196
|
+
:external_callbacks_count => 12,
|
197
|
+
:external_targets_count => 3,
|
198
|
+
:external_conditionals_count => 2,
|
199
|
+
:calculated_permutations => 11
|
200
|
+
}
|
201
|
+
|
202
|
+
assert_equal expected, report.to_hash
|
203
|
+
end
|
204
|
+
```
|
205
|
+
|
206
|
+
When change happens and that test fails it outputs a helpful error message.
|
207
|
+
|
208
|
+
```
|
209
|
+
---------------------------------------------
|
210
|
+
Please /cc @github/migration on the PR if you
|
211
|
+
have to update this test to make it pass.
|
212
|
+
---------------------------------------------
|
213
|
+
```
|
214
|
+
|
165
215
|
## License
|
166
216
|
|
167
217
|
The MIT License (MIT)
|
data/arca.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "arca"
|
3
|
-
spec.version = "2.1.
|
3
|
+
spec.version = "2.1.3"
|
4
4
|
spec.date = "2015-08-07"
|
5
5
|
spec.summary = "ActiveRecord callback analyzer"
|
6
6
|
spec.description = "Arca is a callback analyzer for ActiveRecord ideally suited for digging yourself out of callback hell"
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/jonmagic/arca"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.add_development_dependency "
|
16
|
+
spec.add_development_dependency "activerecord", "~> 4.2"
|
17
17
|
spec.add_development_dependency "minitest", "~> 5.7"
|
18
18
|
spec.add_development_dependency "pry", "~> 0.10"
|
19
19
|
spec.add_development_dependency "rake", "~> 10.4"
|
@@ -10,7 +10,7 @@ module Arca
|
|
10
10
|
#
|
11
11
|
# model - Arca::Model instance.
|
12
12
|
# callback_data - Hash with callback data collected by Arca::Collector.
|
13
|
-
def initialize(model
|
13
|
+
def initialize(model, callback_data)
|
14
14
|
@model = model
|
15
15
|
@callback_symbol = callback_data.fetch(:callback_symbol)
|
16
16
|
@callback_file_path = callback_data.fetch(:callback_file_path)
|
data/lib/arca/model.rb
CHANGED
@@ -64,10 +64,7 @@ module Arca
|
|
64
64
|
@analyzed_callbacks ||= CALLBACKS.inject({}) do |result, callback_symbol|
|
65
65
|
Array(callbacks[callback_symbol]).each do |callback_data|
|
66
66
|
result[callback_symbol] ||= []
|
67
|
-
callback_analysis = CallbackAnalysis.new(
|
68
|
-
:model => self,
|
69
|
-
:callback_data => callback_data
|
70
|
-
})
|
67
|
+
callback_analysis = CallbackAnalysis.new(self, callback_data)
|
71
68
|
|
72
69
|
unless callback_analysis.target_file_path_active_record?
|
73
70
|
result[callback_symbol] << callback_analysis
|
@@ -6,44 +6,35 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def announce_save
|
9
|
-
@announce_save ||= Arca::CallbackAnalysis.new({
|
10
|
-
:
|
11
|
-
:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
:conditional_symbol => nil,
|
17
|
-
:conditional_target_symbol => nil
|
18
|
-
}
|
9
|
+
@announce_save ||= Arca::CallbackAnalysis.new(model, {
|
10
|
+
:callback_symbol => :after_save,
|
11
|
+
:callback_file_path => "#{Arca.root_path}/test/fixtures/announcements.rb",
|
12
|
+
:callback_line_number => 4,
|
13
|
+
:target_symbol => :announce_save,
|
14
|
+
:conditional_symbol => nil,
|
15
|
+
:conditional_target_symbol => nil
|
19
16
|
})
|
20
17
|
end
|
21
18
|
|
22
19
|
def set_title
|
23
|
-
@set_title ||= Arca::CallbackAnalysis.new({
|
24
|
-
:
|
25
|
-
:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
:conditional_symbol => nil,
|
31
|
-
:conditional_target_symbol => nil
|
32
|
-
}
|
20
|
+
@set_title ||= Arca::CallbackAnalysis.new(model, {
|
21
|
+
:callback_symbol=>:before_save,
|
22
|
+
:callback_file_path => "#{Arca.root_path}/test/fixtures/ticket.rb",
|
23
|
+
:callback_line_number => 5,
|
24
|
+
:target_symbol => :set_title,
|
25
|
+
:conditional_symbol => nil,
|
26
|
+
:conditional_target_symbol => nil
|
33
27
|
})
|
34
28
|
end
|
35
29
|
|
36
30
|
def upcase_title
|
37
|
-
@upcase_title ||= Arca::CallbackAnalysis.new({
|
38
|
-
:
|
39
|
-
:
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
:conditional_symbol => :if,
|
45
|
-
:conditional_target_symbol => :title_is_a_shout?
|
46
|
-
}
|
31
|
+
@upcase_title ||= Arca::CallbackAnalysis.new(model, {
|
32
|
+
:callback_symbol => :before_save,
|
33
|
+
:callback_file_path => "#{Arca.root_path}/test/fixtures/ticket.rb",
|
34
|
+
:callback_line_number => 6,
|
35
|
+
:target_symbol => :upcase_title,
|
36
|
+
:conditional_symbol => :if,
|
37
|
+
:conditional_target_symbol => :title_is_a_shout?
|
47
38
|
})
|
48
39
|
end
|
49
40
|
|
data/test/test_helper.rb
CHANGED
@@ -4,7 +4,10 @@ require "minitest/autorun"
|
|
4
4
|
require "arca"
|
5
5
|
|
6
6
|
class ActiveRecord::Base
|
7
|
-
|
7
|
+
if respond_to?(:raise_in_transactional_callbacks)
|
8
|
+
self.raise_in_transactional_callbacks = true
|
9
|
+
end
|
10
|
+
|
8
11
|
include Arca::Collector
|
9
12
|
end
|
10
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Hoyt
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2015-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
@@ -73,11 +73,14 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
76
78
|
- Gemfile
|
77
|
-
- Gemfile.lock
|
78
79
|
- README.md
|
79
80
|
- Rakefile
|
80
81
|
- arca.gemspec
|
82
|
+
- gemfiles/Gemfile_activerecord-3.2
|
83
|
+
- gemfiles/Gemfile_activerecord-4.2
|
81
84
|
- lib/arca.rb
|
82
85
|
- lib/arca/callback_analysis.rb
|
83
86
|
- lib/arca/collector.rb
|
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
arca (1.0.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
coderay (1.1.0)
|
10
|
-
method_source (0.8.2)
|
11
|
-
minitest (5.7.0)
|
12
|
-
pry (0.10.1)
|
13
|
-
coderay (~> 1.1.0)
|
14
|
-
method_source (~> 0.8.1)
|
15
|
-
slop (~> 3.4)
|
16
|
-
rake (10.4.2)
|
17
|
-
slop (3.5.0)
|
18
|
-
|
19
|
-
PLATFORMS
|
20
|
-
ruby
|
21
|
-
|
22
|
-
DEPENDENCIES
|
23
|
-
arca!
|
24
|
-
minitest (~> 5.7)
|
25
|
-
pry (~> 0.10.1)
|
26
|
-
rake (~> 10.4)
|