arca 2.1.3 → 2.2.0
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/arca.gemspec +1 -1
- data/lib/arca/callback_analysis.rb +1 -1
- data/lib/arca/collector.rb +14 -3
- data/test/fixtures/announcements.rb +12 -1
- data/test/lib/arca/callback_analysis_test.rb +2 -2
- data/test/lib/arca/collector_test.rb +31 -3
- data/test/lib/arca/model_test.rb +5 -5
- data/test/lib/arca/report_test.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0591095b4b348fcbd76cf72ef3cea8aeecb8016
|
4
|
+
data.tar.gz: bd32d70f3788e5238761d3368b6944b923860c54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea28b0b452751d96980314871b79df23b5ea261e9defbc9e3f331690d1c5ca4f4fee7b8c6c65461298faab770034c1c58e752b89cd9f5aa833b032b784a5c5b
|
7
|
+
data.tar.gz: 5477fd14ed651d2681b8167db4ef3ee5ea60ae7246f73cb9e9e36c025df1f2747678d1db410b47113d8f78985bde696cf25b2cfee7e4b69bd90e92f35f001250
|
data/arca.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "arca"
|
3
|
-
spec.version = "2.
|
3
|
+
spec.version = "2.2.0"
|
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"
|
@@ -80,7 +80,7 @@ module Arca
|
|
80
80
|
# Public: Boolean representing whether the callback target is located in the
|
81
81
|
# same file where the callback is defined.
|
82
82
|
def external_target?
|
83
|
-
return false if target_symbol == :
|
83
|
+
return false if target_symbol == :inline
|
84
84
|
target_file_path != callback_file_path
|
85
85
|
end
|
86
86
|
|
data/lib/arca/collector.rb
CHANGED
@@ -33,9 +33,21 @@ module Arca
|
|
33
33
|
# Duplicate args before modifying.
|
34
34
|
args_copy = args.dup
|
35
35
|
|
36
|
-
# Add target_symbol :
|
36
|
+
# Add target_symbol :inline to args_copy if a block, Proc, or Class
|
37
|
+
# was given.
|
37
38
|
if block
|
38
|
-
args_copy.unshift(:
|
39
|
+
args_copy.unshift(:inline)
|
40
|
+
elsif args_copy.first.kind_of?(Proc)
|
41
|
+
args_copy.shift
|
42
|
+
args_copy.unshift(:inline)
|
43
|
+
elsif !args_copy.first.kind_of?(Symbol)
|
44
|
+
class_or_instance = args_copy.shift
|
45
|
+
|
46
|
+
if class_or_instance.class == Class
|
47
|
+
args_copy.unshift(class_or_instance.name.to_sym)
|
48
|
+
else
|
49
|
+
args_copy.unshift(class_or_instance.class.name.to_sym)
|
50
|
+
end
|
39
51
|
end
|
40
52
|
|
41
53
|
# Get the options hash from the end of the args Array if it exists.
|
@@ -78,7 +90,6 @@ module Arca
|
|
78
90
|
:conditional_symbol => conditional_symbol,
|
79
91
|
:conditional_target_symbol => conditional_target_symbol
|
80
92
|
}
|
81
|
-
|
82
93
|
end
|
83
94
|
|
84
95
|
# Bind the callback method to self and call it with args.
|
@@ -1,8 +1,19 @@
|
|
1
|
+
class SomeCallbackClass
|
2
|
+
def after_destroy(record)
|
3
|
+
puts "after_destroy announcement callback"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
module Announcements
|
2
8
|
def self.included(base)
|
3
9
|
base.class_eval do
|
4
|
-
before_save { puts "
|
10
|
+
before_save { puts "before_save announcement callback" }
|
5
11
|
after_save :announce_save
|
12
|
+
|
13
|
+
around_save lambda { puts "around_save announcement callback" }
|
14
|
+
before_destroy -> { puts "before_destroy announcement callback" }
|
15
|
+
|
16
|
+
after_destroy SomeCallbackClass.new
|
6
17
|
end
|
7
18
|
end
|
8
19
|
|
@@ -75,7 +75,7 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def test_target_line_number
|
78
|
-
assert_equal
|
78
|
+
assert_equal 20, announce_save.target_line_number
|
79
79
|
assert_equal 8, set_title.target_line_number
|
80
80
|
assert_equal 16, upcase_title.target_line_number
|
81
81
|
end
|
@@ -87,7 +87,7 @@ class Arca::CallbackAnalysisTest < Minitest::Test
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def test_lines_to_target
|
90
|
-
assert_equal
|
90
|
+
assert_equal 16, announce_save.lines_to_target
|
91
91
|
assert_equal 3, set_title.lines_to_target
|
92
92
|
assert_equal 10, upcase_title.lines_to_target
|
93
93
|
end
|
@@ -6,11 +6,15 @@ class Arca::CollectorTest < Minitest::Test
|
|
6
6
|
assert_equal 1, callbacks[:after_save].size
|
7
7
|
assert_equal 4, callbacks[:before_save].size
|
8
8
|
assert_equal 1, callbacks[:after_commit].size
|
9
|
+
assert_equal 1, callbacks[:around_save].size
|
10
|
+
assert_equal 1, callbacks[:before_destroy].size
|
11
|
+
assert_equal 1, callbacks[:after_destroy].size
|
12
|
+
|
9
13
|
|
10
14
|
callback = callbacks[:after_save][0]
|
11
15
|
assert_equal :after_save, callback[:callback_symbol]
|
12
16
|
assert_match "test/fixtures/announcements.rb", callback[:callback_file_path]
|
13
|
-
assert_equal
|
17
|
+
assert_equal 11, callback[:callback_line_number]
|
14
18
|
assert_equal :announce_save, callback[:target_symbol]
|
15
19
|
assert_nil callback[:conditional_symbol]
|
16
20
|
assert_nil callback[:conditional_target_symbol]
|
@@ -18,8 +22,8 @@ class Arca::CollectorTest < Minitest::Test
|
|
18
22
|
callback = callbacks[:before_save][0]
|
19
23
|
assert_equal :before_save, callback[:callback_symbol]
|
20
24
|
assert_match "test/fixtures/announcements.rb", callback[:callback_file_path]
|
21
|
-
assert_equal
|
22
|
-
assert_equal :
|
25
|
+
assert_equal 10, callback[:callback_line_number]
|
26
|
+
assert_equal :inline, callback[:target_symbol]
|
23
27
|
assert_nil callback[:conditional_symbol]
|
24
28
|
assert_nil callback[:conditional_target_symbol]
|
25
29
|
|
@@ -54,6 +58,30 @@ class Arca::CollectorTest < Minitest::Test
|
|
54
58
|
assert_equal :update_timeline, callback[:target_symbol]
|
55
59
|
assert_equal :on, callback[:conditional_symbol]
|
56
60
|
assert_equal [:create, :destroy], callback[:conditional_target_symbol]
|
61
|
+
|
62
|
+
callback = callbacks[:around_save][0]
|
63
|
+
assert_equal :around_save, callback[:callback_symbol]
|
64
|
+
assert_match "test/fixtures/announcements.rb", callback[:callback_file_path]
|
65
|
+
assert_equal 13, callback[:callback_line_number]
|
66
|
+
assert_equal :inline, callback[:target_symbol]
|
67
|
+
assert_nil callback[:conditional_symbol]
|
68
|
+
assert_nil callback[:conditional_target_symbol]
|
69
|
+
|
70
|
+
callback = callbacks[:before_destroy][0]
|
71
|
+
assert_equal :before_destroy, callback[:callback_symbol]
|
72
|
+
assert_match "test/fixtures/announcements.rb", callback[:callback_file_path]
|
73
|
+
assert_equal 14, callback[:callback_line_number]
|
74
|
+
assert_equal :inline, callback[:target_symbol]
|
75
|
+
assert_nil callback[:conditional_symbol]
|
76
|
+
assert_nil callback[:conditional_target_symbol]
|
77
|
+
|
78
|
+
callback = callbacks[:after_destroy][0]
|
79
|
+
assert_equal :after_destroy, callback[:callback_symbol]
|
80
|
+
assert_match "test/fixtures/announcements.rb", callback[:callback_file_path]
|
81
|
+
assert_equal 16, callback[:callback_line_number]
|
82
|
+
assert_equal :SomeCallbackClass, callback[:target_symbol]
|
83
|
+
assert_nil callback[:conditional_symbol]
|
84
|
+
assert_nil callback[:conditional_target_symbol]
|
57
85
|
end
|
58
86
|
|
59
87
|
def test_callback_is_reapplied_with_original_args
|
data/test/lib/arca/model_test.rb
CHANGED
@@ -33,24 +33,24 @@ class Arca::ModelTest < Minitest::Test
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_analyzed_callbacks_array
|
36
|
-
assert_equal
|
36
|
+
assert_equal 9, model.analyzed_callbacks_array.size
|
37
37
|
assert model.analyzed_callbacks_array[0].is_a?(Arca::CallbackAnalysis)
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_analyzed_callbacks_count
|
41
|
-
assert_equal
|
41
|
+
assert_equal 9, model.analyzed_callbacks_count
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_lines_between_count
|
45
|
-
assert_equal
|
45
|
+
assert_equal 16, model.lines_between_count
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_external_callbacks_count
|
49
|
-
assert_equal
|
49
|
+
assert_equal 5, model.external_callbacks_count
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_external_targets_count
|
53
|
-
assert_equal
|
53
|
+
assert_equal 1, model.external_targets_count
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_external_conditionals_count
|