kalibro_client 0.0.1 → 0.0.2

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/features/kalibro_configuration/all.feature +6 -6
  4. data/features/kalibro_configuration/creation.feature +5 -5
  5. data/features/kalibro_configuration/destroy.feature +6 -6
  6. data/features/kalibro_configuration/metric_configurations.feature +4 -4
  7. data/features/{range → kalibro_range}/destroy.feature +2 -2
  8. data/features/{range → kalibro_range}/exists.feature +2 -2
  9. data/features/{range → kalibro_range}/find.feature +2 -2
  10. data/features/{range → kalibro_range}/ranges_of.feature +4 -4
  11. data/features/{range → kalibro_range}/save.feature +2 -2
  12. data/features/kalibro_range/update.feature +54 -0
  13. data/features/metric_configuration/creation.feature +2 -2
  14. data/features/metric_configuration/destroy.feature +2 -2
  15. data/features/metric_configuration/find.feature +2 -2
  16. data/features/metric_configuration/metric_configurations_of.feature +8 -8
  17. data/features/metric_result/descendant_values.feature +2 -2
  18. data/features/metric_result/history_of.feature +2 -2
  19. data/features/metric_result/metric_results_of.feature +2 -2
  20. data/features/module_result/children.feature +2 -2
  21. data/features/module_result/find.feature +2 -2
  22. data/features/module_result/history_of.feature +2 -2
  23. data/features/processing/first_processing_after.feature +2 -2
  24. data/features/processing/first_processing_of.feature +2 -2
  25. data/features/processing/has_processing.feature +2 -2
  26. data/features/processing/has_processing_after.feature +2 -2
  27. data/features/processing/has_processing_before.feature +2 -2
  28. data/features/processing/has_ready_processing.feature +2 -2
  29. data/features/processing/last_processing_before.feature +2 -2
  30. data/features/processing/last_processing_of.feature +2 -2
  31. data/features/processing/last_processing_state_of.feature +2 -2
  32. data/features/processing/last_ready_processing_of.feature +2 -2
  33. data/features/processing/processing_of.feature +4 -4
  34. data/features/processing/processing_with_date_of.feature +4 -4
  35. data/features/project/update.feature +13 -0
  36. data/features/repository/all.feature +1 -1
  37. data/features/repository/cancel_processing.feature +1 -1
  38. data/features/repository/destroy.feature +1 -1
  39. data/features/repository/exists.feature +1 -1
  40. data/features/repository/find.feature +1 -1
  41. data/features/repository/of.feature +1 -1
  42. data/features/repository/process.feature +2 -2
  43. data/features/step_definitions/kalibro_configuration_steps.rb +40 -0
  44. data/features/step_definitions/metric_configuration_steps.rb +9 -9
  45. data/features/step_definitions/module_result_steps.rb +1 -1
  46. data/features/step_definitions/project_steps.rb +12 -0
  47. data/features/step_definitions/range_steps.rb +25 -1
  48. data/features/step_definitions/reading_steps.rb +1 -1
  49. data/features/step_definitions/repository_steps.rb +1 -1
  50. data/lib/kalibro_client/entities/base.rb +53 -19
  51. data/lib/kalibro_client/entities/configurations/base.rb +4 -1
  52. data/lib/kalibro_client/entities/configurations/kalibro_configuration.rb +1 -1
  53. data/lib/kalibro_client/entities/configurations/kalibro_range.rb +8 -8
  54. data/lib/kalibro_client/entities/configurations/metric_configuration.rb +7 -5
  55. data/lib/kalibro_client/entities/configurations/reading.rb +4 -4
  56. data/lib/kalibro_client/entities/configurations/reading_group.rb +4 -0
  57. data/lib/kalibro_client/entities/processor/base.rb +2 -1
  58. data/lib/kalibro_client/entities/processor/kalibro_module.rb +1 -0
  59. data/lib/kalibro_client/entities/processor/metric_collector_details.rb +7 -2
  60. data/lib/kalibro_client/entities/processor/metric_result.rb +9 -10
  61. data/lib/kalibro_client/entities/processor/module_result.rb +10 -2
  62. data/lib/kalibro_client/entities/processor/processing.rb +26 -10
  63. data/lib/kalibro_client/entities/processor/project.rb +4 -0
  64. data/lib/kalibro_client/entities/processor/repository.rb +63 -4
  65. data/lib/kalibro_client/helpers/date_attributes.rb +11 -0
  66. data/lib/kalibro_client/helpers/request_methods.rb +9 -0
  67. data/lib/kalibro_client/version.rb +1 -1
  68. data/spec/entities/base_spec.rb +106 -24
  69. data/spec/entities/configurations/kalibro_configuration_spec.rb +8 -8
  70. data/spec/entities/configurations/kalibro_range_spec.rb +18 -24
  71. data/spec/entities/configurations/metric_configuration_spec.rb +22 -23
  72. data/spec/entities/configurations/reading_group_spec.rb +27 -0
  73. data/spec/entities/configurations/reading_spec.rb +15 -7
  74. data/spec/entities/processor/metric_collector_details_spec.rb +19 -7
  75. data/spec/entities/processor/metric_result_spec.rb +40 -54
  76. data/spec/entities/processor/module_result_spec.rb +52 -3
  77. data/spec/entities/processor/processing_spec.rb +35 -92
  78. data/spec/entities/processor/project_spec.rb +52 -5
  79. data/spec/entities/processor/repository_spec.rb +255 -5
  80. data/spec/factories/kalibro_configurations.rb +3 -3
  81. data/spec/factories/kalibro_ranges.rb +9 -3
  82. data/spec/factories/metrics.rb +1 -1
  83. data/spec/factories/readings.rb +1 -1
  84. data/spec/factories/repositories.rb +1 -1
  85. data/spec/helpers/date_attributes_spec.rb +30 -0
  86. metadata +21 -14
  87. data/features/step_definitions/configuration_steps.rb +0 -40
@@ -1,8 +1,11 @@
1
+ require 'kalibro_client/helpers/date_attributes'
2
+
1
3
  module KalibroClient
2
4
  module Entities
3
5
  module Configurations
4
6
  class Base < KalibroClient::Entities::Base
5
- attr_accessor :created_at, :updated_at
7
+ include DateAttributes
8
+
6
9
  def self.address
7
10
  :configurations_address
8
11
  end
@@ -5,7 +5,7 @@
5
5
  # it under the terms of the GNU General Public License as published by
6
6
  # the Free Software Foundation, either version 3 of the License, or
7
7
  # (at your option) any later version.
8
- #
8
+ #
9
9
  # This program is distributed in the hope that it will be useful,
10
10
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -25,16 +25,12 @@ module KalibroClient
25
25
  @id = value.to_i
26
26
  end
27
27
 
28
- def reading_id=(value)
29
- @reading_id = value.to_i
28
+ def metric_configuration_id=(value)
29
+ @metric_configuration_id = value.to_i
30
30
  end
31
31
 
32
- def beginning=(value)
33
- @beginning = value == "-INF" ? value : value.to_f
34
- end
35
-
36
- def end=(value)
37
- @end = value == "INF" ? value : value.to_f
32
+ def reading_id=(value)
33
+ @reading_id = value.to_i
38
34
  end
39
35
 
40
36
  def label
@@ -68,6 +64,10 @@ module KalibroClient
68
64
  "metric_configurations/#{metric_configuration_id}"
69
65
  end
70
66
 
67
+ def update_prefix
68
+ "metric_configurations/#{metric_configuration_id}"
69
+ end
70
+
71
71
  def destroy_prefix
72
72
  "metric_configurations/#{metric_configuration_id}"
73
73
  end
@@ -35,12 +35,10 @@ module KalibroClient
35
35
 
36
36
  def metric=(value)
37
37
  if value.is_a?(Hash)
38
- if value['type'] == "NativeMetricSnapshot" || value[:type] == "NativeMetricSnapshot"
38
+ if value['type'] == "NativeMetricSnapshot"
39
39
  @metric = KalibroClient::Entities::Miscellaneous::NativeMetric.to_object(value)
40
- elsif value['type'] == "CompoundMetricSnapshot" || value[:type] == "CompoundMetricSnapshot"
41
- @metric = KalibroClient::Entities::Miscellaneous::CompoundMetric.to_object(value)
42
40
  else
43
- @metric = KalibroClient::Entities::Miscellaneous::Metric.to_object(value)
41
+ @metric = KalibroClient::Entities::Miscellaneous::CompoundMetric.to_object(value)
44
42
  end
45
43
  elsif value.is_a?(KalibroClient::Entities::Miscellaneous::Metric)
46
44
  @metric = value
@@ -70,7 +68,7 @@ module KalibroClient
70
68
 
71
69
  def self.find(id)
72
70
  metric_configuration = request(':id', {id: id}, :get)
73
- raise KalibroClient::Errors::RecordNotFound unless metric_configuration['error'].nil?
71
+ raise KalibroClient::Errors::RecordNotFound unless metric_configuration['errors'].nil?
74
72
  return new(metric_configuration['metric_configuration'])
75
73
  end
76
74
 
@@ -82,6 +80,10 @@ module KalibroClient
82
80
  end
83
81
  end
84
82
 
83
+ def kalibro_ranges
84
+ KalibroClient::Entities::Configurations::KalibroRange.create_objects_array_from_hash(self.class.request(':id/kalibro_ranges', {id: id}, :get))
85
+ end
86
+
85
87
  private
86
88
 
87
89
  def save_params
@@ -25,10 +25,6 @@ module KalibroClient
25
25
  @id = value.to_i
26
26
  end
27
27
 
28
- def grade=(value)
29
- @grade = value.to_f
30
- end
31
-
32
28
  def reading_group_id=(value)
33
29
  @reading_group_id = value.to_i
34
30
  end
@@ -50,6 +46,10 @@ module KalibroClient
50
46
  def destroy_prefix
51
47
  "reading_groups/#{reading_group_id}"
52
48
  end
49
+
50
+ def update_prefix
51
+ "reading_groups/#{reading_group_id}"
52
+ end
53
53
  end
54
54
  end
55
55
  end
@@ -28,6 +28,10 @@ module KalibroClient
28
28
  def self.all
29
29
  create_objects_array_from_hash(request('', {}, :get))
30
30
  end
31
+
32
+ def readings
33
+ KalibroClient::Entities::Configurations::Reading.create_objects_array_from_hash(self.class.request(':id/readings', {id: @id}, :get))
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -1,11 +1,12 @@
1
1
  require 'json'
2
+ require 'kalibro_client/helpers/date_attributes'
2
3
 
3
4
  module KalibroClient
4
5
  module Entities
5
6
  module Processor
6
7
  class Base < KalibroClient::Entities::Base
8
+ include DateAttributes
7
9
 
8
- attr_accessor :created_at, :updated_at
9
10
  def self.address
10
11
  :processor_address
11
12
  end
@@ -20,6 +20,7 @@ module KalibroClient
20
20
  class KalibroModule < KalibroClient::Entities::Processor::Base
21
21
 
22
22
  attr_accessor :name, :granlrty, :id, :long_name, :module_result_id
23
+ alias_method :granularity, :granlrty
23
24
 
24
25
  end
25
26
  end
@@ -23,15 +23,20 @@ module KalibroClient
23
23
  def supported_metrics=(value)
24
24
  @supported_metrics = {}
25
25
  value.each do |code, metric|
26
- @supported_metrics[code] = KalibroClient::Entities::Miscellaneous::Metric.new(metric[:type], metric[:name], metric[:code], metric[:scope])
26
+ @supported_metrics[code] = KalibroClient::Entities::Miscellaneous::NativeMetric.new(metric["name"], metric["code"], metric["scope"], metric["languages"], metric["metric_collector_name"])
27
27
  end
28
28
  end
29
29
 
30
- def metric(name)
30
+ def find_metric_by_name(name)
31
31
  metric = self.supported_metrics.find {|code, metric| metric.name == name}
32
32
  metric.nil? ? nil : metric.last
33
33
  end
34
34
 
35
+ def find_metric_by_code(metric_code)
36
+ metric = self.supported_metrics.find {|code, metric| metric.code == metric_code}
37
+ metric.nil? ? nil : metric.last
38
+ end
39
+
35
40
  def self.find_by_name(metric_collector_name)
36
41
  begin
37
42
  new request(:find, {name: metric_collector_name})["metric_collector_details"]
@@ -20,8 +20,9 @@ module KalibroClient
20
20
  class MetricResult < KalibroClient::Entities::Processor::Base
21
21
 
22
22
  attr_accessor :id, :value, :aggregated_value, :module_result_id, :metric_configuration_id
23
+ attr_reader :metric_configuration
23
24
 
24
- def initialize(attributes={})
25
+ def initialize(attributes={}, persisted=false)
25
26
  value = attributes["value"]
26
27
  @value = (value == "NaN") ? attributes["aggregated_value"].to_f : value.to_f
27
28
  attributes.each do |field, value|
@@ -30,25 +31,22 @@ module KalibroClient
30
31
  end
31
32
  end
32
33
  @kalibro_errors = []
34
+ @persisted = persisted
33
35
  end
34
36
 
35
37
  def id=(value)
36
38
  @id = value.to_i
37
39
  end
38
40
 
41
+ def metric_configuration_id=(value)
42
+ self.metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.request(":id", {id: value.to_i}, :get)["metric_configuration"]
43
+ end
44
+
39
45
  def metric_configuration=(value)
40
46
  @metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.to_object value
41
47
  @metric_configuration_id = @metric_configuration.id
42
48
  end
43
49
 
44
- def metric_configuration
45
- unless @metric_configuration.nil?
46
- return @metric_configuration
47
- end
48
- @metric_configuration = KalibroClient::Entities::Configurations::MetricConfiguration.find @metric_configuration_id
49
- return @metric_configuration
50
- end
51
-
52
50
  def value=(value)
53
51
  @value = value.to_f
54
52
  end
@@ -63,7 +61,8 @@ module KalibroClient
63
61
  end
64
62
 
65
63
  def self.metric_results_of(module_result_id)
66
- create_objects_array_from_hash ModuleResult.request(":id/metric_results", {id: module_result_id}, :get)
64
+ puts "DEPRECATED: MetricResult.metric_results_of"
65
+ KalibroClient::Entities::Processor::ModuleResult.find(module_result_id).metric_results
67
66
  end
68
67
 
69
68
  def self.history_of(metric_name, kalibro_module_id, repository_id)
@@ -51,6 +51,10 @@ module KalibroClient
51
51
  @processing_id = value.to_i
52
52
  end
53
53
 
54
+ def processing
55
+ KalibroClient::Entities::Processor::Processing.find(self.processing_id)
56
+ end
57
+
54
58
  def grade=(value)
55
59
  @grade = value.to_f
56
60
  end
@@ -67,8 +71,8 @@ module KalibroClient
67
71
  !self.folder?
68
72
  end
69
73
 
70
- def self.history_of(module_result_id)
71
- response = self.create_array_from_hash(self.request('history_of', {id: module_result_id})['date_module_results'])
74
+ def self.history_of(module_result, repository_id)
75
+ response = self.create_array_from_hash(Repository.request(':id/module_result_history_of', {id: repository_id, kalibro_module_id: module_result.kalibro_module.id})['date_module_results'])
72
76
  response.map do |date_module_result_pair|
73
77
  date_module_result = KalibroClient::Entities::Miscellaneous::DateModuleResult.new
74
78
  date_module_result.date = date_module_result_pair.first
@@ -76,6 +80,10 @@ module KalibroClient
76
80
  date_module_result
77
81
  end
78
82
  end
83
+
84
+ def metric_results
85
+ MetricResult.create_objects_array_from_hash self.class.request(":id/metric_results", {id: self.id}, :get)
86
+ end
79
87
  end
80
88
  end
81
89
  end
@@ -65,43 +65,59 @@ module KalibroClient
65
65
  end
66
66
 
67
67
  def self.has_processing(repository_id)
68
- Repository.request("#{repository_id}/has_processing")['has_processing']
68
+ puts "DEPRECATED: Processing.has_processing"
69
+ repository(repository_id).has_processing
69
70
  end
70
71
 
71
72
  def self.has_ready_processing(repository_id)
72
- Repository.request("#{repository_id}/has_ready_processing", {}, :get)['has_ready_processing']
73
+ puts "DEPRECATED: Processing.has_ready_processing"
74
+ repository(repository_id).has_ready_processing
73
75
  end
74
76
 
75
77
  def self.has_processing_after(repository_id, date)
76
- Repository.request("#{repository_id}/has_processing/after", {:date => date})['has_processing_in_time']
78
+ puts "DEPRECATED: Processing.has_processing_after"
79
+ repository(repository_id).has_processing_after(date)
77
80
  end
78
81
 
79
82
  def self.has_processing_before(repository_id, date)
80
- Repository.request("#{repository_id}/has_processing/before", {:date => date})['has_processing_in_time']
83
+ puts "DEPRECATED: Processing.has_processing_before"
84
+ repository(repository_id).has_processing_before(date)
81
85
  end
82
86
 
83
87
  def self.last_processing_state_of(repository_id)
84
- Repository.request("#{repository_id}/last_processing_state", {}, :get)['processing_state']
88
+ puts "DEPRECATED: Processing.last_processing_state_of"
89
+ repository(repository_id).last_processing_state
85
90
  end
86
91
 
87
92
  def self.last_ready_processing_of(repository_id)
88
- new(Repository.request(':id/last_ready_processing', {id: repository_id}, :get)['last_ready_processing'])
93
+ puts "DEPRECATED: Processing.last_ready_processing_of"
94
+ repository(repository_id).last_ready_processing
89
95
  end
90
96
 
91
97
  def self.first_processing_of(repository_id)
92
- new(Repository.request("#{repository_id}/first_processing")['processing'])
98
+ puts "DEPRECATED: Processing.first_processing_of"
99
+ repository(repository_id).first_processing
93
100
  end
94
101
 
95
102
  def self.last_processing_of(repository_id)
96
- new(Repository.request("#{repository_id}/last_processing")['processing'])
103
+ puts "DEPRECATED: Processing.last_processing_of"
104
+ repository(repository_id).last_processing
97
105
  end
98
106
 
99
107
  def self.first_processing_after(repository_id, date)
100
- new(Repository.request("#{repository_id}/first_processing/after", {:date => date})["processing"])
108
+ puts "DEPRECATED: Processing.first_processing_after"
109
+ repository(repository_id).first_processing_after(date)
101
110
  end
102
111
 
103
112
  def self.last_processing_before(repository_id, date)
104
- new(Repository.request("#{repository_id}/last_processing/before", {:date => date})['processing'])
113
+ puts "DEPRECATED: Processing.last_processing_before"
114
+ repository(repository_id).last_processing_before(date)
115
+ end
116
+
117
+ private
118
+
119
+ def self.repository(id)
120
+ Repository.find(id)
105
121
  end
106
122
  end
107
123
  end
@@ -28,6 +28,10 @@ module KalibroClient
28
28
  def self.all
29
29
  create_objects_array_from_hash(request('', {}, :get))
30
30
  end
31
+
32
+ def repositories
33
+ Repository.create_objects_array_from_hash(self.class.request(':id/repositories', {id: id}, :get))
34
+ end
31
35
  end
32
36
  end
33
37
  end
@@ -19,7 +19,7 @@ module KalibroClient
19
19
  module Processor
20
20
  class Repository < KalibroClient::Entities::Processor::Base
21
21
 
22
- attr_accessor :id, :name, :description, :license, :period, :scm_type, :address, :configuration_id, :project_id, :send_email, :code_directory
22
+ attr_accessor :id, :name, :description, :license, :period, :scm_type, :address, :kalibro_configuration_id, :project_id, :send_email, :code_directory
23
23
 
24
24
  def self.repository_types
25
25
  request('types', {}, :get)['types'].to_a
@@ -37,8 +37,8 @@ module KalibroClient
37
37
  @period = value.to_i
38
38
  end
39
39
 
40
- def configuration_id=(value)
41
- @configuration_id = value.to_i
40
+ def kalibro_configuration_id=(value)
41
+ @kalibro_configuration_id = value.to_i
42
42
  end
43
43
 
44
44
  def project_id=(value)
@@ -50,7 +50,66 @@ module KalibroClient
50
50
  end
51
51
 
52
52
  def cancel_processing_of_repository
53
- self.class.request('cancel_process', {id: self.id})
53
+ self.class.request(':id/cancel_process', {id: self.id}, :get)
54
+ end
55
+
56
+ def processing
57
+ if has_ready_processing
58
+ last_ready_processing
59
+ else
60
+ last_processing
61
+ end
62
+ end
63
+
64
+ def processing_with_date(date)
65
+ date = date.is_a?(String) ? DateTime.parse(date) : date
66
+ if has_processing_after(date)
67
+ first_processing_after(date)
68
+ elsif has_processing_before(date)
69
+ last_processing_before(date)
70
+ else
71
+ nil
72
+ end
73
+ end
74
+
75
+ def has_processing
76
+ self.class.request("#{self.id}/has_processing", {}, :get)['has_processing']
77
+ end
78
+
79
+ def has_ready_processing
80
+ self.class.request("#{self.id}/has_ready_processing", {}, :get)['has_ready_processing']
81
+ end
82
+
83
+ def has_processing_after(date)
84
+ self.class.request("#{self.id}/has_processing/after", {:date => date})['has_processing_in_time']
85
+ end
86
+
87
+ def has_processing_before(date)
88
+ self.class.request("#{self.id}/has_processing/before", {:date => date})['has_processing_in_time']
89
+ end
90
+
91
+ def last_processing_state
92
+ self.class.request("#{self.id}/last_processing_state", {}, :get)['processing_state']
93
+ end
94
+
95
+ def last_ready_processing
96
+ Processing.new(self.class.request(':id/last_ready_processing', {id: self.id}, :get)['last_ready_processing'])
97
+ end
98
+
99
+ def first_processing
100
+ Processing.new(self.class.request("#{self.id}/first_processing")['processing'])
101
+ end
102
+
103
+ def last_processing
104
+ Processing.new(self.class.request("#{self.id}/last_processing")['processing'])
105
+ end
106
+
107
+ def first_processing_after(date)
108
+ Processing.new(self.class.request("#{self.id}/first_processing/after", {:date => date})["processing"])
109
+ end
110
+
111
+ def last_processing_before(date)
112
+ Processing.new(self.class.request("#{self.id}/last_processing/before", {:date => date})['processing'])
54
113
  end
55
114
 
56
115
  def self.all
@@ -0,0 +1,11 @@
1
+ module DateAttributes
2
+ attr_reader :created_at, :updated_at
3
+
4
+ def created_at=(value)
5
+ @created_at = DateTime.parse(value)
6
+ end
7
+
8
+ def updated_at=(value)
9
+ @updated_at = DateTime.parse(value)
10
+ end
11
+ end
@@ -30,6 +30,7 @@ module RequestMethods
30
30
  def destroy_action
31
31
  ":id"
32
32
  end
33
+ alias_method :update_action, :destroy_action
33
34
 
34
35
  def destroy_params
35
36
  {id: self.id}
@@ -39,6 +40,14 @@ module RequestMethods
39
40
  ""
40
41
  end
41
42
 
43
+ def update_params
44
+ {instance_class_name.underscore.to_sym => self.to_hash, :id => self.id}
45
+ end
46
+
47
+ def update_prefix
48
+ ""
49
+ end
50
+
42
51
  module ClassMethods
43
52
  def exists_action
44
53
  ":id/exists"