private_please 0.0.5 → 0.1.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 +7 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -5
- data/CHANGELOG +4 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -98
- data/Rakefile +6 -2
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/private_please/config.rb +15 -0
- data/lib/private_please/methods_calls_tracker.rb +44 -0
- data/lib/private_please/reporting/simple_text.rb +43 -0
- data/lib/private_please/reporting/templates/simple.txt.erb +11 -0
- data/lib/private_please/storage/called_methods_memory_store.rb +20 -0
- data/lib/private_please/tracking/debug/trace_point_data_logger.rb +81 -0
- data/lib/private_please/tracking/method_details.rb +27 -0
- data/lib/private_please/tracking/result.rb +25 -0
- data/lib/private_please/tracking/trace_point_details.rb +41 -0
- data/lib/private_please/tracking/trace_point_processor.rb +71 -0
- data/lib/private_please/utils/ruby_utils.rb +44 -0
- data/lib/private_please/utils/source_file_utils.rb +20 -0
- data/lib/private_please/utils/two_level_stack.rb +13 -0
- data/lib/private_please/version.rb +2 -1
- data/lib/private_please.rb +27 -34
- data/private_please.gemspec +32 -25
- metadata +106 -185
- data/Guardfile +0 -8
- data/LICENSE +0 -22
- data/TODO +0 -20
- data/bin/pp_ruby +0 -62
- data/bin/ruby_pp +0 -62
- data/doc/dev_notes.txt +0 -32
- data/doc/fixtures/complex.rb +0 -103
- data/doc/fixtures/empty_class.rb +0 -7
- data/doc/fixtures/fixture_helper.rb +0 -8
- data/doc/fixtures/sample.rb +0 -57
- data/lib/private_please/candidate.rb +0 -49
- data/lib/private_please/report/table.rb +0 -44
- data/lib/private_please/report.rb +0 -6
- data/lib/private_please/reporter/base.rb +0 -14
- data/lib/private_please/reporter/data_compiler.rb +0 -82
- data/lib/private_please/reporter/helpers/options_helpers.rb +0 -37
- data/lib/private_please/reporter/helpers/text_table_helpers.rb +0 -9
- data/lib/private_please/reporter/simple_text.rb +0 -18
- data/lib/private_please/reporter/templates/simple.txt.erb +0 -80
- data/lib/private_please/reporter.rb +0 -8
- data/lib/private_please/ruby_backports.rb +0 -22
- data/lib/private_please/storage/calls_store.rb +0 -41
- data/lib/private_please/storage/candidates_store.rb +0 -52
- data/lib/private_please/storage/methods_names.rb +0 -10
- data/lib/private_please/storage/methods_names_bucket.rb +0 -69
- data/lib/private_please/storage.rb +0 -8
- data/lib/private_please/tracking/extension.rb +0 -12
- data/lib/private_please/tracking/instrumentor.rb +0 -49
- data/lib/private_please/tracking/instruments_all_methods_below.rb +0 -28
- data/lib/private_please/tracking/instruments_automatically_all_methods_in_all_classes.rb +0 -68
- data/lib/private_please/tracking/line_change_tracker.rb +0 -26
- data/lib/private_please/tracking/load_utils/gem_utils.rb +0 -49
- data/lib/private_please/tracking/load_utils/standard_lib_utils.rb +0 -38
- data/lib/private_please/tracking/load_utils.rb +0 -32
- data/lib/private_please/tracking/utils.rb +0 -34
- data/lib/private_please/tracking.rb +0 -49
- data/sample.rb +0 -68
- data/spec/01_tracking_candidate_methods/excluding_gems_and_standard_libraries_spec.rb +0 -31
- data/spec/01_tracking_candidate_methods/explicitely_with_the_private_please_command_spec.rb +0 -118
- data/spec/01_tracking_candidate_methods/load_utils_spec.rb +0 -40
- data/spec/01_tracking_candidate_methods/systematically_in_auto_mode_spec.rb +0 -185
- data/spec/03_logging_calls_on_candidate_methods_spec.rb +0 -37
- data/spec/04_instrumented_program_activity_observation_result_spec.rb +0 -86
- data/spec/05_reporting/report_table_spec.rb +0 -51
- data/spec/06_at_exit_spec.rb +0 -18
- data/spec/_helpers/assert_helpers.rb +0 -76
- data/spec/fixtures/bug_22.rb +0 -17
- data/spec/fixtures/bug_30.rb +0 -6
- data/spec/fixtures/issue_25.rb +0 -12
- data/spec/fixtures/sample_class_for_report.rb +0 -56
- data/spec/fixtures/sample_class_with_all_calls_combinations.rb +0 -69
- data/spec/sandbox/Gemfile +0 -4
- data/spec/sandbox/Gemfile.lock +0 -14
- data/spec/sandbox/README.txt +0 -26
- data/spec/sandbox/normal.rb +0 -7
- data/spec/sandbox/normal_prepended_with_require.rb +0 -8
- data/spec/spec_helper.rb +0 -38
- data/spec/units/calls_store_spec.rb +0 -15
- data/spec/units/candidates_store_spec.rb +0 -55
- data/spec/units/reporter/data_compiler_spec.rb +0 -12
- data/spec/units/reporter/fixtures/simple_case_1.rb +0 -30
- data/spec/units/reporter/fixtures/simple_case_2.rb +0 -55
data/Guardfile
DELETED
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Alain Ravet
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/TODO
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
install only in classes (? and modules)
|
3
|
-
def self.install
|
4
|
-
Object.send :include, PrivatePlease::Tracking::Extension
|
5
|
-
^^^^^^
|
6
|
-
TOO WIDE
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
DSL
|
11
|
-
- observe class methods too
|
12
|
-
|
13
|
-
Report :
|
14
|
-
- option : show file and line number of good candidate definition
|
15
|
-
- option : show code snippet around the good candidate
|
16
|
-
- display list of methods that were never called
|
17
|
-
- display candidates that are already private
|
18
|
-
|
19
|
-
Doc
|
20
|
-
- write README
|
data/bin/pp_ruby
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# ----------------------------------------------------------------------------------- #
|
4
|
-
# Effects : inject PrivatePlease tracking in the command #
|
5
|
-
# ----------------------------------------------------------------------------------- #
|
6
|
-
# $ pp_ruby normal.rb #
|
7
|
-
# $ bundle exec pp_ruby normal.rb #
|
8
|
-
# become #
|
9
|
-
# $ ruby -rubygems -e "require 'private_please' ; load 'normal.rb'" #
|
10
|
-
# $ bundle exec ruby -e "require 'private_please' ; load 'normal.rb'" #
|
11
|
-
# ----------------------------------------------------------------------------------- #
|
12
|
-
|
13
|
-
|
14
|
-
########################
|
15
|
-
# Extract command parts :
|
16
|
-
########################
|
17
|
-
|
18
|
-
switches, filename, arguments = [], nil, []
|
19
|
-
loop do
|
20
|
-
case ARGV[0]
|
21
|
-
when '-r' then switches << ARGV.shift << ARGV.shift
|
22
|
-
when '-e' then switches << ARGV.shift << ARGV.shift.inspect
|
23
|
-
when /^-\S/ then switches << ARGV.shift
|
24
|
-
else break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
filename = ARGV.shift
|
28
|
-
arguments = ARGV
|
29
|
-
|
30
|
-
|
31
|
-
######################
|
32
|
-
# Assemble new command :
|
33
|
-
######################
|
34
|
-
|
35
|
-
# ? called with `bundle exec ruby .....`
|
36
|
-
in_bundler_mode = !!defined?(Bundler)
|
37
|
-
|
38
|
-
program = in_bundler_mode ?
|
39
|
-
'bundle exec ruby' :
|
40
|
-
'ruby'
|
41
|
-
|
42
|
-
command = if filename
|
43
|
-
rubygems_or_not = in_bundler_mode ? nil : " -rubygems"
|
44
|
-
[ program,
|
45
|
-
switches,
|
46
|
-
%|#{rubygems_or_not} -e "require 'private_please' ; load '#{filename}'"| ,
|
47
|
-
arguments
|
48
|
-
]
|
49
|
-
else
|
50
|
-
[ program,
|
51
|
-
switches,
|
52
|
-
arguments
|
53
|
-
]
|
54
|
-
end.flatten.compact.join(' ')
|
55
|
-
|
56
|
-
|
57
|
-
#############################
|
58
|
-
# Execute transformed command :
|
59
|
-
#############################
|
60
|
-
|
61
|
-
puts "Executing: #{command}"
|
62
|
-
puts `#{command}`
|
data/bin/ruby_pp
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# ----------------------------------------------------------------------------------- #
|
4
|
-
# Effects : inject PrivatePlease tracking in the command #
|
5
|
-
# ----------------------------------------------------------------------------------- #
|
6
|
-
# $ pp_ruby normal.rb #
|
7
|
-
# $ bundle exec pp_ruby normal.rb #
|
8
|
-
# become #
|
9
|
-
# $ ruby -rubygems -e "require 'private_please' ; load 'normal.rb'" #
|
10
|
-
# $ bundle exec ruby -e "require 'private_please' ; load 'normal.rb'" #
|
11
|
-
# ----------------------------------------------------------------------------------- #
|
12
|
-
|
13
|
-
|
14
|
-
########################
|
15
|
-
# Extract command parts :
|
16
|
-
########################
|
17
|
-
|
18
|
-
switches, filename, arguments = [], nil, []
|
19
|
-
loop do
|
20
|
-
case ARGV[0]
|
21
|
-
when '-r' then switches << ARGV.shift << ARGV.shift
|
22
|
-
when '-e' then switches << ARGV.shift << ARGV.shift.inspect
|
23
|
-
when /^-\S/ then switches << ARGV.shift
|
24
|
-
else break
|
25
|
-
end
|
26
|
-
end
|
27
|
-
filename = ARGV.shift
|
28
|
-
arguments = ARGV
|
29
|
-
|
30
|
-
|
31
|
-
######################
|
32
|
-
# Assemble new command :
|
33
|
-
######################
|
34
|
-
|
35
|
-
# ? called with `bundle exec ruby .....`
|
36
|
-
in_bundler_mode = !!defined?(Bundler)
|
37
|
-
|
38
|
-
program = in_bundler_mode ?
|
39
|
-
'bundle exec ruby' :
|
40
|
-
'ruby'
|
41
|
-
|
42
|
-
command = if filename
|
43
|
-
rubygems_or_not = in_bundler_mode ? nil : " -rubygems"
|
44
|
-
[ program,
|
45
|
-
switches,
|
46
|
-
%|#{rubygems_or_not} -e "require 'private_please' ; load '#{filename}'"| ,
|
47
|
-
arguments
|
48
|
-
]
|
49
|
-
else
|
50
|
-
[ program,
|
51
|
-
switches,
|
52
|
-
arguments
|
53
|
-
]
|
54
|
-
end.flatten.compact.join(' ')
|
55
|
-
|
56
|
-
|
57
|
-
#############################
|
58
|
-
# Execute transformed command :
|
59
|
-
#############################
|
60
|
-
|
61
|
-
puts "Executing: #{command}"
|
62
|
-
puts `#{command}`
|
data/doc/dev_notes.txt
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
Q: Where is the TODO list :
|
2
|
-
A: https://github.com/alainravet/private_please/issues?state=open
|
3
|
-
|
4
|
-
How to run the tests :
|
5
|
-
========================
|
6
|
-
|
7
|
-
$ cd <project root>
|
8
|
-
$ bundle exec rspec
|
9
|
-
or
|
10
|
-
$ bundle exec guard # (see https://github.com/alainravet/private_please/issues/10)
|
11
|
-
|
12
|
-
|
13
|
-
How to test on multiple versions of Ruby :
|
14
|
-
============================================
|
15
|
-
# install rbenv + multiple versions of Ruby
|
16
|
-
# install the rbenv-each plugin
|
17
|
-
$ rbenv each -v bundle exec ruby -Ilib rspec
|
18
|
-
|
19
|
-
|
20
|
-
How to run the latest PP code on a custom Ruby code sample :
|
21
|
-
======================================================
|
22
|
-
|
23
|
-
$ cd <project root>
|
24
|
-
$ bundle exec ruby -Ilib doc/fixtures/complex.rb
|
25
|
-
|
26
|
-
How to display more than the list of methods that can be made private ?
|
27
|
-
======================================================
|
28
|
-
|
29
|
-
$ export PP_OPTIONS="--show-bad-candidates --show-never-called"
|
30
|
-
$ bundle exec ruby -Ilib doc/fixtures/complex.rb
|
31
|
-
or
|
32
|
-
$ PP_OPTIONS="--show-bad-candidates --show-never-called" bundle exec ruby -Ilib doc/fixtures/complex.rb
|
data/doc/fixtures/complex.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
load File.dirname(__FILE__) + '/fixture_helper.rb'
|
2
|
-
|
3
|
-
module ComplexReport
|
4
|
-
|
5
|
-
class Class1
|
6
|
-
def initialize
|
7
|
-
super
|
8
|
-
end
|
9
|
-
def sole_entry_point
|
10
|
-
instance_m_1
|
11
|
-
self.class.class_m_1
|
12
|
-
self.class.c_make_internal_method_calls
|
13
|
-
end
|
14
|
-
|
15
|
-
def instance_m_1; end
|
16
|
-
def instance_m_2; end
|
17
|
-
|
18
|
-
def self.class_m_1;
|
19
|
-
class_m_2
|
20
|
-
end
|
21
|
-
def self.class_m_2; end
|
22
|
-
|
23
|
-
|
24
|
-
def self.c_make_internal_method_calls
|
25
|
-
class_m_1
|
26
|
-
new.instance_m_2
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
#-----------------------------------------------------------------------------------------------------------------------
|
33
|
-
|
34
|
-
ComplexReport::Class1.new.sole_entry_point
|
35
|
-
|
36
|
-
module ComplexReport
|
37
|
-
###########################################
|
38
|
-
class Simple # Internal calls : #
|
39
|
-
# -> called methods are _GOOD CANDIDATES_ #
|
40
|
-
def make_internal_calls ###########################################
|
41
|
-
instance_m_1 # i -> i
|
42
|
-
self.class.class_m_1 # i -> C
|
43
|
-
self.class.c_make_internal_method_calls # i -> C --> C
|
44
|
-
end # +-> i
|
45
|
-
|
46
|
-
def self.c_make_internal_method_calls #
|
47
|
-
class_m_1 # C -> C
|
48
|
-
new.instance_m_2 # C -> i
|
49
|
-
end #
|
50
|
-
end
|
51
|
-
|
52
|
-
#######################################################
|
53
|
-
class AnotherClass # External calls (would fail if methods were private) #
|
54
|
-
# -> called methods are _BAD CANDIDATES_ #
|
55
|
-
def make_external_calls #######################################################
|
56
|
-
Simple.new.instance_m_1 # i -> i
|
57
|
-
Simple .class_m_1 # i -> C
|
58
|
-
self.class.c_make_external_calls # i -> C -> i
|
59
|
-
end # -> C
|
60
|
-
def self.c_make_external_calls #
|
61
|
-
Simple.new.instance_m_1 # C -> i
|
62
|
-
Simple .class_m_1 # C -> C
|
63
|
-
end #
|
64
|
-
def call_the_candidate_from_inside_and_outside
|
65
|
-
make_external_calls
|
66
|
-
Simple.new.make_internal_calls
|
67
|
-
Simple.a_class_method_via_module_Extra
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
#-----------------------------------------------------------------------------------------------------------------------
|
72
|
-
module Extra
|
73
|
-
def self.included(base)
|
74
|
-
base.extend(ClassMethods)
|
75
|
-
end
|
76
|
-
def im_never_called ; raise; end
|
77
|
-
module ClassMethods
|
78
|
-
def a_class_method_via_module_Extra ; end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
class Simple
|
84
|
-
def self.not_a_candidate_c1;
|
85
|
-
class_m_2
|
86
|
-
end
|
87
|
-
|
88
|
-
include Extra
|
89
|
-
def instance_m_1; end
|
90
|
-
def instance_m_2; end
|
91
|
-
|
92
|
-
def self.class_m_1;
|
93
|
-
class_m_2
|
94
|
-
end
|
95
|
-
def self.class_m_2; end
|
96
|
-
|
97
|
-
def never_called_1; end
|
98
|
-
def self.class_never_called_1; end
|
99
|
-
end
|
100
|
-
#-----------------------------------------------------------------------------------------------------------------------
|
101
|
-
end
|
102
|
-
|
103
|
-
ComplexReport::AnotherClass.new.call_the_candidate_from_inside_and_outside
|
data/doc/fixtures/empty_class.rb
DELETED
data/doc/fixtures/sample.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
load File.dirname(__FILE__) + '/fixture_helper.rb'
|
2
|
-
|
3
|
-
module ReportSample
|
4
|
-
###########################################
|
5
|
-
class Simple # Internal calls : #
|
6
|
-
# -> called methods are _GOOD CANDIDATES_ #
|
7
|
-
def make_internal_calls ###########################################
|
8
|
-
instance_m_1 # i -> i
|
9
|
-
self.class.class_m_1 # i -> C
|
10
|
-
self.class.c_make_internal_method_calls # i -> C --> C
|
11
|
-
end # +-> i
|
12
|
-
|
13
|
-
def self.c_make_internal_method_calls #
|
14
|
-
class_m_1 # C -> C
|
15
|
-
new.instance_m_2 # C -> i
|
16
|
-
end #
|
17
|
-
end
|
18
|
-
|
19
|
-
#######################################################
|
20
|
-
class AnotherClass # External calls (would fail if methods were private) #
|
21
|
-
# -> called methods are _BAD CANDIDATES_ #
|
22
|
-
def make_external_calls #######################################################
|
23
|
-
Simple.new.instance_m_1 # i -> i
|
24
|
-
Simple .class_m_1 # i -> C
|
25
|
-
self.class.c_make_external_calls # i -> C -> i
|
26
|
-
end # -> C
|
27
|
-
def self.c_make_external_calls #
|
28
|
-
Simple.new.instance_m_1 # C -> i
|
29
|
-
Simple .class_m_1 # C -> C
|
30
|
-
end #
|
31
|
-
def call_the_candidate_from_inside_and_outside
|
32
|
-
make_external_calls
|
33
|
-
Simple.new.make_internal_calls
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
#-----------------------------------------------------------------------------------------------------------------------
|
38
|
-
class Simple
|
39
|
-
def self.not_a_candidate_c1;
|
40
|
-
class_m_2
|
41
|
-
end
|
42
|
-
|
43
|
-
def instance_m_1; end
|
44
|
-
def instance_m_2; end
|
45
|
-
|
46
|
-
def self.class_m_1;
|
47
|
-
class_m_2
|
48
|
-
end
|
49
|
-
def self.class_m_2; end
|
50
|
-
|
51
|
-
def never_called_1; end
|
52
|
-
def self.class_never_called_1; end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
#-----------------------------------------------------------------------------------------------------------------------
|
56
|
-
|
57
|
-
ReportSample::Simple.new.make_internal_calls
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Holds the details of 1 method that was marked via `private_please`.
|
2
|
-
|
3
|
-
module PrivatePlease
|
4
|
-
class Candidate
|
5
|
-
|
6
|
-
def initialize(klass, method_name, is_instance_method)
|
7
|
-
@klass, @method_name, @is_instance_method = klass, method_name, is_instance_method
|
8
|
-
@klass_name = klass.to_s
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.for_instance_method(klass, method_name)
|
12
|
-
new(klass, method_name, true)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.for_class_method(klass, method_name)
|
16
|
-
new(klass, method_name, false)
|
17
|
-
end
|
18
|
-
|
19
|
-
#----------------------------------------------------------------------------
|
20
|
-
# QUERIES:
|
21
|
-
#----------------------------------------------------------------------------
|
22
|
-
|
23
|
-
attr_reader :klass,
|
24
|
-
:klass_name,
|
25
|
-
:method_name,
|
26
|
-
:is_instance_method
|
27
|
-
|
28
|
-
alias_method :instance_method?, :is_instance_method
|
29
|
-
|
30
|
-
def already_instrumented?
|
31
|
-
instrumented_candidates_store.stored?(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
#----------------------------------------------------------------------------
|
35
|
-
# SUGAR:
|
36
|
-
#----------------------------------------------------------------------------
|
37
|
-
|
38
|
-
def mark_as_instrumented
|
39
|
-
instrumented_candidates_store.store(self)
|
40
|
-
end
|
41
|
-
|
42
|
-
#----------------------------------------------------------------------------
|
43
|
-
private
|
44
|
-
|
45
|
-
def instrumented_candidates_store
|
46
|
-
PrivatePlease.candidates_store
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|