kalibro_client 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b40775ac3e5ba10762848b6572733224f37a152a
|
4
|
+
data.tar.gz: 92263bcca84854b2fc945eed763cf8508fc4e5c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e14134d85a08877a3839550c8e97c8b8c73b390042b24c6068723bf5304af652d0a046bf3795458c00f15639a1b621bf0e74146b562f0b9944db23186af183
|
7
|
+
data.tar.gz: bb36487be04498b65d0f4bd3007ca6e886e78f41ffb06995377af90f7a795fb174bb0dc86ddd92e400482be7dc1d359eca3a3d48a38e6bd304ad633662c6160a
|
@@ -2,12 +2,21 @@ module KalibroClient
|
|
2
2
|
module Entities
|
3
3
|
module Miscellaneous
|
4
4
|
class Granularity
|
5
|
-
|
5
|
+
include Comparable
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
GRANULARITIES = [:METHOD, :CLASS, :PACKAGE, :SOFTWARE, :FUNCTION]
|
8
|
+
|
9
|
+
GRANULARITIES.each do |name|
|
10
|
+
self.const_set(name, name)
|
11
|
+
end
|
12
|
+
|
13
|
+
PARENTS = {
|
14
|
+
METHOD: CLASS,
|
15
|
+
CLASS: PACKAGE,
|
16
|
+
PACKAGE: SOFTWARE,
|
17
|
+
SOFTWARE: SOFTWARE,
|
18
|
+
FUNCTION: PACKAGE
|
19
|
+
}
|
11
20
|
|
12
21
|
attr_reader :type
|
13
22
|
|
@@ -20,45 +29,41 @@ module KalibroClient
|
|
20
29
|
end
|
21
30
|
|
22
31
|
def parent
|
23
|
-
|
24
|
-
|
32
|
+
parent_type = PARENTS[self.type]
|
33
|
+
raise ArgumentError.new("Not supported granularity type #{type}") if parent_type.nil?
|
34
|
+
|
35
|
+
return self if self.type == parent_type
|
36
|
+
Granularity.new(parent_type)
|
25
37
|
end
|
26
38
|
|
27
39
|
def to_s
|
28
40
|
self.type.to_s
|
29
41
|
end
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
|
43
|
+
# FYI: this is a spaceship operator
|
44
|
+
def <=>(other)
|
45
|
+
return nil if [[:FUNCTION, :METHOD], [:METHOD, :FUNCTION]].include?([self.type, other.type])
|
34
46
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
def >=(other_granularity)
|
44
|
-
(self > other_granularity) || (self == other_granularity)
|
47
|
+
if self.type == other.type
|
48
|
+
return 0
|
49
|
+
elsif self.is_lower_than?(other.type)
|
50
|
+
return -1
|
51
|
+
else
|
52
|
+
return 1
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
|
-
def
|
48
|
-
|
49
|
-
end
|
56
|
+
def is_lower_than?(other_type)
|
57
|
+
current_type = self.type
|
50
58
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
elsif self > other_granularity
|
55
|
-
return 1
|
56
|
-
else
|
57
|
-
return 0
|
59
|
+
while current_type != PARENTS[current_type]
|
60
|
+
return true if PARENTS[current_type] == other_type
|
61
|
+
current_type = PARENTS[current_type]
|
58
62
|
end
|
63
|
+
|
64
|
+
return false
|
59
65
|
end
|
60
66
|
end
|
61
|
-
|
62
67
|
end
|
63
68
|
end
|
64
69
|
end
|
@@ -32,6 +32,14 @@ describe KalibroClient::Entities::Miscellaneous::Granularity do
|
|
32
32
|
expect(subject.parent.type).to eq(KalibroClient::Entities::Miscellaneous::Granularity::CLASS)
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
context 'with a FUNCTION granularity' do
|
37
|
+
subject { FactoryGirl.build(:granularity, type: KalibroClient::Entities::Miscellaneous::Granularity::FUNCTION) }
|
38
|
+
|
39
|
+
it 'should return PACKAGE' do
|
40
|
+
expect(subject.parent.type).to eq(KalibroClient::Entities::Miscellaneous::Granularity::PACKAGE)
|
41
|
+
end
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
45
|
describe 'Comparison Operators' do
|
@@ -92,6 +100,18 @@ describe KalibroClient::Entities::Miscellaneous::Granularity do
|
|
92
100
|
expect(subject <=> other_granularity).to eq(1)
|
93
101
|
end
|
94
102
|
end
|
103
|
+
|
104
|
+
context 'comparing unrelated ones' do
|
105
|
+
let(:function_granularity) { FactoryGirl.build(:granularity, type: KalibroClient::Entities::Miscellaneous::Granularity::FUNCTION) }
|
106
|
+
let(:method_granularity) { FactoryGirl.build(:granularity, type: KalibroClient::Entities::Miscellaneous::Granularity::METHOD) }
|
107
|
+
|
108
|
+
it 'should raise an ArgumentError' do
|
109
|
+
expect { function_granularity < method_granularity }.to raise_error(ArgumentError)
|
110
|
+
expect { function_granularity <= method_granularity }.to raise_error(ArgumentError)
|
111
|
+
expect { function_granularity >= method_granularity }.to raise_error(ArgumentError)
|
112
|
+
expect { function_granularity > method_granularity }.to raise_error(ArgumentError)
|
113
|
+
end
|
114
|
+
end
|
95
115
|
end
|
96
116
|
|
97
117
|
describe 'to_s' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kalibro_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Quadros Miranda
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -379,7 +379,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
379
379
|
version: '0'
|
380
380
|
requirements: []
|
381
381
|
rubyforge_project:
|
382
|
-
rubygems_version: 2.4.
|
382
|
+
rubygems_version: 2.4.5
|
383
383
|
signing_key:
|
384
384
|
specification_version: 4
|
385
385
|
summary: KalibroClient is a communication interface with the KalibroProcessor and
|