kalibro_client 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e7df405fbb5caaf2ed0998437a1e6a4ef66b74e
4
- data.tar.gz: c6123a2a752d3750f33e04f428395b5bf98c1bb6
3
+ metadata.gz: b40775ac3e5ba10762848b6572733224f37a152a
4
+ data.tar.gz: 92263bcca84854b2fc945eed763cf8508fc4e5c2
5
5
  SHA512:
6
- metadata.gz: 44c1230696f6f271e0619473edad2700caf0c3f34f9b8f2ea1ff4df3fc77efb300c91b386c4671e7e909b4ac106ea1b3884246dec111831098ebea5f9044f25c
7
- data.tar.gz: 8011b114efdaf7ce12c0e2f234aeaae49d99e80c19c8d0d912b57b027d7da9e519a233105f5a6e11b10eb8d42f27f22250d0274e6de25d63fc0b3055db63126c
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
- GRANULARITIES = [:METHOD, :CLASS, :PACKAGE, :SOFTWARE]
5
+ include Comparable
6
6
 
7
- METHOD = GRANULARITIES[0]
8
- CLASS = GRANULARITIES[1]
9
- PACKAGE = GRANULARITIES[2]
10
- SOFTWARE = GRANULARITIES[3]
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
- return self if self.type == SOFTWARE
24
- return Granularity.new(GRANULARITIES[GRANULARITIES.find_index(self.type) + 1])
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
- def <(other_granularity)
32
- GRANULARITIES.find_index(self.type) < GRANULARITIES.find_index(other_granularity.type)
33
- end
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
- def ==(other_granularity)
36
- self.type == other_granularity.type
37
- end
38
-
39
- def <=(other_granularity)
40
- (self < other_granularity) || (self == other_granularity)
41
- end
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 >(other_granularity)
48
- !(self <= other_granularity)
49
- end
56
+ def is_lower_than?(other_type)
57
+ current_type = self.type
50
58
 
51
- def <=>(other_granularity)
52
- if self < other_granularity
53
- return -1
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
@@ -15,5 +15,5 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  module KalibroClient
18
- VERSION = "0.4.0"
18
+ VERSION = "0.5.0"
19
19
  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.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-07-06 00:00:00.000000000 Z
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.6
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