kalibro_client 1.1.0 → 1.2.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: 898bf1fce5f6d3c85b0c2e11e9e8f378f1bfc2e4
4
- data.tar.gz: a25aaa22d3f6b64a04ff42a174e730cf230a7c35
3
+ metadata.gz: 15bcca85f96a24bd55b802949805c93d4db2e5ad
4
+ data.tar.gz: 83b823a0de3a999ff5465073b0df0bc40eb9faed
5
5
  SHA512:
6
- metadata.gz: f6a8c927614532f3eb376b14c074bcc60277ee1460acc729838c04b8144c49094fc9da631140544071b00913ad9ac56b6a9004f3f66a192ac3bcc62fd1b7dd53
7
- data.tar.gz: 7ec5f6c9d83e108e80f9013022929e0d8a013dbe4ab208ebcfa5a40dac3a001b08513a75d56d653543c27e1c99db211eed6ce8516bffc227b078c05fca06994b
6
+ metadata.gz: ab72cff243dc5c1303e799cf051938935aea76fec5886a089a99d9ad753ae571492fb56603cca72ea68b31da9558e604ae24a42f8bb44d38bd04ddbcebc44176
7
+ data.tar.gz: 2b28c6858132fd53576bfa144ad4ed57b1b947673ad4c779045d4fd25538a7b260a3ec3b95a33b4d5f7a088eb587f07b1300b61c7c252ac432db80ede00c18cf
@@ -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
@@ -18,7 +18,7 @@ module KalibroClient
18
18
  module Entities
19
19
  module Processor
20
20
  class MetricCollectorDetails < KalibroClient::Entities::Processor::Base
21
- attr_accessor :name, :description, :supported_metrics, :wanted_metrics, :processing
21
+ attr_accessor :name, :description, :supported_metrics
22
22
 
23
23
  def supported_metrics=(value)
24
24
  @supported_metrics = {}
@@ -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 = "1.1.0"
18
+ VERSION = "1.2.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: 1.1.0
4
+ version: 1.2.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