descendants_tracker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +21 -12
- data/Gemfile +3 -52
- data/Gemfile.devtools +55 -0
- data/LICENSE +2 -1
- data/README.md +22 -29
- data/Rakefile +2 -6
- data/config/devtools.yml +4 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/mutant.yml +3 -0
- data/config/{site.reek → reek.yml} +19 -13
- data/config/rubocop.yml +58 -0
- data/descendants_tracker.gemspec +6 -5
- data/lib/descendants_tracker.rb +27 -5
- data/lib/descendants_tracker/version.rb +7 -2
- data/spec/spec_helper.rb +23 -4
- data/spec/support/config_alias.rb +2 -0
- data/spec/unit/descendants_tracker/add_descendant_spec.rb +11 -9
- data/spec/unit/descendants_tracker/descendants_spec.rb +4 -2
- data/spec/unit/descendants_tracker/inherited_spec.rb +26 -0
- metadata +69 -87
- data/config/roodi.yml +0 -18
- data/spec/shared/command_method_behavior.rb +0 -7
- data/spec/shared/each_method_behaviour.rb +0 -15
- data/spec/shared/hash_method_behavior.rb +0 -17
- data/spec/shared/idempotent_method_behavior.rb +0 -7
- data/spec/shared/invertible_method_behaviour.rb +0 -9
- data/tasks/metrics/ci.rake +0 -9
- data/tasks/metrics/flay.rake +0 -45
- data/tasks/metrics/flog.rake +0 -49
- data/tasks/metrics/heckle.rake +0 -208
- data/tasks/metrics/metric_fu.rake +0 -31
- data/tasks/metrics/reek.rake +0 -21
- data/tasks/metrics/roodi.rake +0 -19
- data/tasks/metrics/yardstick.rake +0 -25
- data/tasks/spec.rake +0 -60
- data/tasks/yard.rake +0 -11
data/lib/descendants_tracker.rb
CHANGED
@@ -1,13 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
# Module that adds descendant tracking to a class
|
2
4
|
module DescendantsTracker
|
3
5
|
|
6
|
+
# @private
|
7
|
+
def self.extended(descendant)
|
8
|
+
setup(descendant)
|
9
|
+
end
|
10
|
+
private_class_method :extended
|
11
|
+
|
12
|
+
# @return [Array]
|
13
|
+
#
|
14
|
+
# @private
|
15
|
+
def self.setup(descendant)
|
16
|
+
descendant.instance_variable_set('@descendants', [])
|
17
|
+
end
|
18
|
+
private_class_method :extended
|
19
|
+
|
4
20
|
# Return the descendants of this class
|
5
21
|
#
|
22
|
+
# @example
|
23
|
+
# descendants = ParentClass.descendants
|
24
|
+
#
|
6
25
|
# @return [Array<Class>]
|
7
26
|
#
|
8
|
-
# @api
|
27
|
+
# @api public
|
9
28
|
def descendants
|
10
|
-
@descendants
|
29
|
+
@descendants
|
11
30
|
end
|
12
31
|
|
13
32
|
# Add the descendant to this class and the superclass
|
@@ -18,8 +37,10 @@ module DescendantsTracker
|
|
18
37
|
#
|
19
38
|
# @api private
|
20
39
|
def add_descendant(descendant)
|
21
|
-
|
22
|
-
|
40
|
+
ancestor = superclass
|
41
|
+
if ancestor.respond_to?(:add_descendant)
|
42
|
+
ancestor.add_descendant(descendant)
|
43
|
+
end
|
23
44
|
descendants.unshift(descendant)
|
24
45
|
self
|
25
46
|
end
|
@@ -30,11 +51,12 @@ private
|
|
30
51
|
#
|
31
52
|
# @param [Class] descendant
|
32
53
|
#
|
33
|
-
# @return [
|
54
|
+
# @return [self]
|
34
55
|
#
|
35
56
|
# @api private
|
36
57
|
def inherited(descendant)
|
37
58
|
super
|
59
|
+
DescendantsTracker.setup(descendant)
|
38
60
|
add_descendant(descendant)
|
39
61
|
end
|
40
62
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
require 'devtools/spec_helper'
|
4
|
+
|
5
|
+
if ENV['COVERAGE'] == 'true'
|
6
|
+
require 'simplecov'
|
7
|
+
require 'coveralls'
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
10
|
+
SimpleCov::Formatter::HTMLFormatter,
|
11
|
+
Coveralls::SimpleCov::Formatter
|
12
|
+
]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
command_name 'spec:unit'
|
16
|
+
add_filter 'config'
|
17
|
+
add_filter 'spec'
|
18
|
+
minimum_coverage 100
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
3
22
|
require 'descendants_tracker'
|
4
|
-
require 'spec'
|
5
|
-
require 'spec/autorun'
|
6
23
|
|
7
24
|
# require spec support files and shared behavior
|
8
|
-
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each
|
25
|
+
Dir[File.expand_path('../{support,shared}/**/*.rb', __FILE__)].each do |file|
|
26
|
+
require file
|
27
|
+
end
|
9
28
|
|
10
|
-
|
29
|
+
RSpec.configure do |config|
|
11
30
|
end
|
@@ -1,24 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe DescendantsTracker, '#add_descendant' do
|
4
6
|
subject { object.add_descendant(descendant) }
|
5
7
|
|
6
8
|
let(:described_class) { Class.new { extend DescendantsTracker } }
|
7
|
-
let(:object) { Class.new(described_class)
|
8
|
-
let(:descendant) { Class.new
|
9
|
+
let(:object) { Class.new(described_class) }
|
10
|
+
let(:descendant) { Class.new }
|
9
11
|
|
10
|
-
|
12
|
+
it_should_behave_like 'a command method'
|
11
13
|
|
12
14
|
it 'prepends the class to the descendants' do
|
13
15
|
object.descendants << original = Class.new
|
14
|
-
expect { subject }.to change { object.descendants.dup }
|
15
|
-
from([
|
16
|
-
to([
|
16
|
+
expect { subject }.to change { object.descendants.dup }
|
17
|
+
.from([original])
|
18
|
+
.to([descendant, original])
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'prepends the class to the superclass descendants' do
|
20
|
-
expect { subject }.to change { object.superclass.descendants.dup }
|
21
|
-
from([
|
22
|
-
to([
|
22
|
+
expect { subject }.to change { object.superclass.descendants.dup }
|
23
|
+
.from([object])
|
24
|
+
.to([descendant, object])
|
23
25
|
end
|
24
26
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe DescendantsTracker, '#descendants' do
|
4
6
|
subject { object.descendants }
|
5
7
|
|
6
8
|
let(:described_class) { Class.new { extend DescendantsTracker } }
|
7
|
-
let(:object) { described_class
|
9
|
+
let(:object) { described_class }
|
8
10
|
|
9
11
|
context 'when there are no descendants' do
|
10
12
|
it_should_behave_like 'an idempotent method'
|
@@ -17,6 +19,6 @@ describe DescendantsTracker, '#descendants' do
|
|
17
19
|
|
18
20
|
it_should_behave_like 'an idempotent method'
|
19
21
|
|
20
|
-
it { should eql([
|
22
|
+
it { should eql([descendant]) }
|
21
23
|
end
|
22
24
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DescendantsTracker, '#inherited' do
|
6
|
+
subject { Class.new(object) }
|
7
|
+
|
8
|
+
let!(:object) { Class.new(superklass).extend(self.class.described_class) }
|
9
|
+
let(:superklass) { Class.new }
|
10
|
+
|
11
|
+
it 'delegates to the superclass #inherited method' do
|
12
|
+
superklass.should_receive(:inherited) do |descendant|
|
13
|
+
descendant.should be_instance_of(Class)
|
14
|
+
descendant.ancestors.should include(object)
|
15
|
+
end
|
16
|
+
subject
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'adds the descendant' do
|
20
|
+
expect(object.descendants).to include(subject)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'sets up descendants in the child class' do
|
24
|
+
expect(subject.descendants).to eql([])
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,141 +1,123 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: descendants_tracker
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 0.0.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Dan Kubb
|
14
8
|
- Piotr Solnica
|
15
9
|
- Markus Schirp
|
16
10
|
autorequire:
|
17
11
|
bindir: bin
|
18
12
|
cert_chain: []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2013-10-05 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
23
16
|
name: rake
|
24
|
-
|
25
|
-
|
26
|
-
none: false
|
27
|
-
requirements:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
28
19
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
segments:
|
32
|
-
- 10
|
33
|
-
- 0
|
34
|
-
- 2
|
35
|
-
version: 10.0.2
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 10.1.0
|
36
22
|
type: :development
|
37
|
-
|
38
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 10.1.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
39
30
|
name: rspec
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.13.0
|
36
|
+
type: :development
|
40
37
|
prerelease: false
|
41
|
-
|
42
|
-
|
43
|
-
requirements:
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
44
40
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.13.0
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: yard
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.8.6.1
|
52
50
|
type: :development
|
53
|
-
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.8.6.1
|
54
57
|
description: Module that adds descendant tracking to a class
|
55
|
-
email:
|
58
|
+
email:
|
56
59
|
- dan.kubb@gmail.com
|
57
60
|
- piotr.solnica@gmail.com
|
58
|
-
- mbj@
|
61
|
+
- mbj@schirp-dso.com
|
59
62
|
executables: []
|
60
|
-
|
61
63
|
extensions: []
|
62
|
-
|
63
|
-
extra_rdoc_files:
|
64
|
+
extra_rdoc_files:
|
64
65
|
- LICENSE
|
65
66
|
- README.md
|
66
67
|
- TODO
|
67
|
-
files:
|
68
|
+
files:
|
68
69
|
- .gitignore
|
69
70
|
- .rvmrc
|
70
71
|
- .travis.yml
|
71
72
|
- Gemfile
|
73
|
+
- Gemfile.devtools
|
72
74
|
- Guardfile
|
73
75
|
- LICENSE
|
74
76
|
- README.md
|
75
77
|
- Rakefile
|
76
78
|
- TODO
|
79
|
+
- config/devtools.yml
|
77
80
|
- config/flay.yml
|
78
81
|
- config/flog.yml
|
79
|
-
- config/
|
80
|
-
- config/
|
82
|
+
- config/mutant.yml
|
83
|
+
- config/reek.yml
|
84
|
+
- config/rubocop.yml
|
81
85
|
- config/yardstick.yml
|
82
86
|
- descendants_tracker.gemspec
|
83
87
|
- lib/descendants_tracker.rb
|
84
88
|
- lib/descendants_tracker/version.rb
|
85
89
|
- spec/rcov.opts
|
86
|
-
- spec/shared/command_method_behavior.rb
|
87
|
-
- spec/shared/each_method_behaviour.rb
|
88
|
-
- spec/shared/hash_method_behavior.rb
|
89
|
-
- spec/shared/idempotent_method_behavior.rb
|
90
|
-
- spec/shared/invertible_method_behaviour.rb
|
91
90
|
- spec/spec.opts
|
92
91
|
- spec/spec_helper.rb
|
93
92
|
- spec/support/config_alias.rb
|
94
93
|
- spec/unit/descendants_tracker/add_descendant_spec.rb
|
95
94
|
- spec/unit/descendants_tracker/descendants_spec.rb
|
96
|
-
-
|
97
|
-
- tasks/metrics/flay.rake
|
98
|
-
- tasks/metrics/flog.rake
|
99
|
-
- tasks/metrics/heckle.rake
|
100
|
-
- tasks/metrics/metric_fu.rake
|
101
|
-
- tasks/metrics/reek.rake
|
102
|
-
- tasks/metrics/roodi.rake
|
103
|
-
- tasks/metrics/yardstick.rake
|
104
|
-
- tasks/spec.rake
|
105
|
-
- tasks/yard.rake
|
95
|
+
- spec/unit/descendants_tracker/inherited_spec.rb
|
106
96
|
homepage: https://github.com/dkubb/descendants_tracker
|
107
97
|
licenses: []
|
108
|
-
|
98
|
+
metadata: {}
|
109
99
|
post_install_message:
|
110
100
|
rdoc_options: []
|
111
|
-
|
112
|
-
require_paths:
|
101
|
+
require_paths:
|
113
102
|
- lib
|
114
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
none: false
|
125
|
-
requirements:
|
126
|
-
- - ">="
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
hash: 3
|
129
|
-
segments:
|
130
|
-
- 0
|
131
|
-
version: "0"
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
132
113
|
requirements: []
|
133
|
-
|
134
114
|
rubyforge_project:
|
135
|
-
rubygems_version:
|
115
|
+
rubygems_version: 2.0.2
|
136
116
|
signing_key:
|
137
|
-
specification_version:
|
117
|
+
specification_version: 4
|
138
118
|
summary: Module that adds descendant tracking to a class
|
139
|
-
test_files:
|
140
|
-
|
119
|
+
test_files:
|
120
|
+
- spec/unit/descendants_tracker/add_descendant_spec.rb
|
121
|
+
- spec/unit/descendants_tracker/descendants_spec.rb
|
122
|
+
- spec/unit/descendants_tracker/inherited_spec.rb
|
141
123
|
has_rdoc:
|
data/config/roodi.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
---
|
2
|
-
AbcMetricMethodCheck: { score: 10.3 }
|
3
|
-
AssignmentInConditionalCheck: { }
|
4
|
-
CaseMissingElseCheck: { }
|
5
|
-
ClassLineCountCheck: { line_count: 293 }
|
6
|
-
ClassNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
7
|
-
ClassVariableCheck: { }
|
8
|
-
CyclomaticComplexityBlockCheck: { complexity: 2 }
|
9
|
-
CyclomaticComplexityMethodCheck: { complexity: 4 }
|
10
|
-
EmptyRescueBodyCheck: { }
|
11
|
-
ForLoopCheck: { }
|
12
|
-
# TODO: decrease line_count to 5 to 10
|
13
|
-
MethodLineCountCheck: { line_count: 14 }
|
14
|
-
MethodNameCheck: { pattern: !ruby/regexp '/\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/' }
|
15
|
-
ModuleLineCountCheck: { line_count: 295 }
|
16
|
-
ModuleNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' }
|
17
|
-
# TODO: decrease parameter_count to 2 or less
|
18
|
-
ParameterNumberCheck: { parameter_count: 3 }
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
shared_examples_for 'an #each method' do
|
4
|
-
it_should_behave_like 'a command method'
|
5
|
-
|
6
|
-
context 'with no block' do
|
7
|
-
subject { object.each }
|
8
|
-
|
9
|
-
it { should be_instance_of(to_enum.class) }
|
10
|
-
|
11
|
-
it 'yields the expected values' do
|
12
|
-
subject.to_a.should eql(object.to_a)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|