runcible 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +2 -1
  2. data/README.md +1 -1
  3. data/Rakefile +16 -10
  4. data/lib/runcible.rb +1 -1
  5. data/lib/runcible/base.rb +24 -29
  6. data/lib/runcible/extensions/consumer.rb +25 -26
  7. data/lib/runcible/extensions/consumer_group.rb +10 -13
  8. data/lib/runcible/extensions/distribution.rb +0 -2
  9. data/lib/runcible/extensions/docker_image.rb +0 -1
  10. data/lib/runcible/extensions/errata.rb +0 -3
  11. data/lib/runcible/extensions/package_category.rb +0 -3
  12. data/lib/runcible/extensions/package_group.rb +0 -2
  13. data/lib/runcible/extensions/puppet_module.rb +0 -3
  14. data/lib/runcible/extensions/repository.rb +88 -72
  15. data/lib/runcible/extensions/rpm.rb +3 -5
  16. data/lib/runcible/extensions/unit.rb +10 -13
  17. data/lib/runcible/extensions/yum_repo_metadata_file.rb +0 -3
  18. data/lib/runcible/instance.rb +22 -28
  19. data/lib/runcible/models/distributor.rb +4 -5
  20. data/lib/runcible/models/docker_distributor.rb +4 -4
  21. data/lib/runcible/models/docker_importer.rb +2 -2
  22. data/lib/runcible/models/export_distributor.rb +1 -1
  23. data/lib/runcible/models/importer.rb +3 -6
  24. data/lib/runcible/models/iso_distributor.rb +3 -3
  25. data/lib/runcible/models/iso_importer.rb +1 -1
  26. data/lib/runcible/models/nodes_http_distributor.rb +0 -1
  27. data/lib/runcible/models/puppet_distributor.rb +2 -2
  28. data/lib/runcible/models/yum_clone_distributor.rb +3 -4
  29. data/lib/runcible/models/yum_distributor.rb +7 -7
  30. data/lib/runcible/models/yum_importer.rb +17 -17
  31. data/lib/runcible/resources/consumer.rb +17 -20
  32. data/lib/runcible/resources/consumer_group.rb +13 -15
  33. data/lib/runcible/resources/content.rb +10 -10
  34. data/lib/runcible/resources/event_notifier.rb +5 -9
  35. data/lib/runcible/resources/repository.rb +23 -23
  36. data/lib/runcible/resources/repository_group.rb +5 -7
  37. data/lib/runcible/resources/repository_schedule.rb +5 -7
  38. data/lib/runcible/resources/role.rb +5 -8
  39. data/lib/runcible/resources/task.rb +10 -13
  40. data/lib/runcible/resources/unit.rb +3 -6
  41. data/lib/runcible/resources/user.rb +7 -10
  42. data/lib/runcible/version.rb +1 -1
  43. metadata +2 -2
@@ -21,7 +21,6 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class DockerImage < Runcible::Extensions::Unit
@@ -21,15 +21,12 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class Errata < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'erratum'
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -21,15 +21,12 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class PackageCategory < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'package_category'
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -21,11 +21,9 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class PackageGroup < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'package_group'
31
29
  end
@@ -21,15 +21,12 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class PuppetModule < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'puppet_module'
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -21,15 +21,14 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class Repository < Runcible::Resources::Repository
28
-
29
27
  # Utility function that allows an importer to be added at repository creation time
30
28
  #
31
29
  # @param [String] id the id of the repository being created
32
- # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or an Importer object
30
+ # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or
31
+ # an Importer object
33
32
  # @return [RestClient::Response] the created repository
34
33
  def create_with_importer(id, importer)
35
34
  create_with_importer_and_distributors(id, importer)
@@ -38,7 +37,8 @@ module Runcible
38
37
  # Utility function that allows distributors to be added at repository creation time
39
38
  #
40
39
  # @param [String] id the id of the repository being created
41
- # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects
40
+ # @param [Array] distributors an array of hashes representing distributors or
41
+ # an array of Distributor objects
42
42
  # @return [RestClient::Response] the created repository
43
43
  def create_with_distributors(id, distributors)
44
44
  create_with_importer_and_distributors(id, nil, distributors)
@@ -47,11 +47,13 @@ module Runcible
47
47
  # Utility function that allows an importer and distributors to be added at repository creation time
48
48
  #
49
49
  # @param [String] id the id of the repository being created
50
- # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or an Importer object
51
- # @param [Array] distributors an array of hashes representing distributors or an array of Distributor objects
50
+ # @param [Hash, Runcible::Extensions::Importer] importer either a hash representing an importer or
51
+ # an Importer object
52
+ # @param [Array] distributors an array of hashes representing distributors or
53
+ # an array of Distributor objects
52
54
  # @param [Hash] optional container for all optional parameters
53
55
  # @return [RestClient::Response] the created repository
54
- def create_with_importer_and_distributors(id, importer, distributors=[], optional={})
56
+ def create_with_importer_and_distributors(id, importer, distributors = [], optional = {})
55
57
  if importer.is_a?(Runcible::Models::Importer)
56
58
  optional[:importer_type_id] = importer.id
57
59
  optional[:importer_config] = importer.config
@@ -62,32 +64,32 @@ module Runcible
62
64
 
63
65
  repo_type = if importer.methods.include?(:repo_type)
64
66
  importer.repo_type
65
- elsif importer.is_a?(Hash) && importer.has_key?(:repo_type)
67
+ elsif importer.is_a?(Hash) && importer.key?(:repo_type)
66
68
  importer[:repo_type]
67
69
  else
68
70
  nil
69
71
  end
70
72
 
71
- if optional.has_key?(:importer_type_id) && repo_type
73
+ if optional.key?(:importer_type_id) && repo_type
72
74
  # pulp needs _repo-type in order to determine the type of repo to create.
73
75
  optional[:notes] = { '_repo-type' => importer.repo_type }
74
76
  end
75
77
 
76
- optional[:distributors] = distributors.collect do |d|
78
+ optional[:distributors] = distributors.map do |d|
77
79
  if d.is_a?(Runcible::Models::Distributor)
78
80
  {'distributor_type_id' => d.type_id,
79
- "distributor_config" => d.config,
80
- "auto_publish" => d.auto_publish,
81
- "distributor_id" => d.id
81
+ 'distributor_config' => d.config,
82
+ 'auto_publish' => d.auto_publish,
83
+ 'distributor_id' => d.id
82
84
  }
83
85
  else
84
86
  {'distributor_type_id' => d['type_id'],
85
- "distributor_config" => d['config'],
86
- "auto_publish" => d['auto_publish'],
87
- "distributor_id" => d['id']
87
+ 'distributor_config' => d['config'],
88
+ 'auto_publish' => d['auto_publish'],
89
+ 'distributor_id' => d['id']
88
90
  }
89
91
  end
90
- end if !distributors.empty?
92
+ end unless distributors.empty?
91
93
  optional[:id] = id
92
94
  create(id, optional)
93
95
  end
@@ -97,7 +99,7 @@ module Runcible
97
99
  # @param [String] repo_id the repository ID
98
100
  # @return [RestClient::Response] a task representing the sync status
99
101
  def sync_status(repo_id)
100
- Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:sync"])
102
+ Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:sync'])
101
103
  end
102
104
 
103
105
  # Retrieves the publish status for a repository
@@ -105,7 +107,7 @@ module Runcible
105
107
  # @param [String] repo_id the repository ID
106
108
  # @return [RestClient::Response] a task representing the sync status
107
109
  def publish_status(repo_id)
108
- Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", "pulp:action:publish"])
110
+ Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:publish'])
109
111
  end
110
112
 
111
113
  # Retrieves a set of repositories by their IDs
@@ -114,34 +116,39 @@ module Runcible
114
116
  # @return [RestClient::Response] the set of repositories requested
115
117
  def search_by_repository_ids(repository_ids)
116
118
  criteria = {:filters =>
117
- { "id" => {"$in" => repository_ids}}
119
+ { 'id' => {'$in' => repository_ids}}
118
120
  }
119
121
  search(criteria)
120
122
  end
121
123
 
122
-
123
124
  # Retrieves the RPM IDs for a single repository
124
125
  #
125
126
  # @param [String] id the ID of the repository
126
127
  # @return [Array<String>] the array of repository RPM IDs
127
128
 
128
129
  def rpm_ids(id)
129
- criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type],
130
- :fields=>{:unit=>[], :association=>['unit_id']}}
131
- self.unit_search(id, criteria).collect{|i| i['unit_id']}
130
+ criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type],
131
+ :fields => {:unit => [], :association => ['unit_id']}}
132
+ self.unit_search(id, criteria).map { |i| i['unit_id'] }
132
133
  rescue RestClient::RequestTimeout
133
- self.logger.warn("Call to rpm_ids timed out")
134
+ self.logger.warn('Call to rpm_ids timed out')
134
135
  # lazy evaluated iterator from zero to infinite
135
- pages = Enumerator.new { |y| page = 0; loop { y << page; page += 1 } }
136
+ pages = Enumerator.new do |y|
137
+ page = 0
138
+ loop do
139
+ y << page
140
+ page += 1
141
+ end
142
+ end
136
143
 
137
- # TODO this is hotfix, pagination support should be added to Runcible
138
- pages.inject([]) do |rpm_ids, page|
144
+ # TODO: this is hotfix, pagination support should be added to Runcible
145
+ pages.reduce([]) do |rpm_ids, page|
139
146
  page_size = 500
140
147
  criteria = { :type_ids => [Runcible::Extensions::Rpm.content_type],
141
148
  :fields => { :unit => [], :association => ['unit_id'] },
142
149
  :limit => page_size,
143
- :skip => 0 + page*page_size }
144
- result = unit_search(id, criteria).collect { |i| i['unit_id'] }
150
+ :skip => 0 + page * page_size }
151
+ result = unit_search(id, criteria).map { |i| i['unit_id'] }
145
152
  rpm_ids.concat(result)
146
153
  if result.empty? || result.size < 500
147
154
  break rpm_ids
@@ -156,8 +163,8 @@ module Runcible
156
163
  # @param [String] id the ID of the repository
157
164
  # @return [RestClient::Response] the set of repository RPMs
158
165
  def rpms(id)
159
- criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type]}
160
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
166
+ criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type]}
167
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
161
168
  end
162
169
 
163
170
  # Retrieves the RPMs by NVRE for a single repository
@@ -168,23 +175,23 @@ module Runcible
168
175
  # @param [String] release the release of the RPMs
169
176
  # @param [String] epoch the epoch of the RPMs
170
177
  # @return [RestClient::Response] the set of repository RPMs
171
- def rpms_by_nvre(id, name, version=nil, release=nil, epoch=nil)
178
+ def rpms_by_nvre(id, name, version = nil, release = nil, epoch = nil)
172
179
  and_condition = []
173
- and_condition << {:name=>name} if name
174
- and_condition << {:version=>version} if version
175
- and_condition << {:release=>release} if release
176
- and_condition << {:epoch=>epoch} if epoch
177
-
178
- criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type],
179
- :filters => {
180
- :unit => {
181
- "$and" => and_condition
182
- }
183
- },
184
- :sort => {
185
- :unit => [ ['name', 'ascending'], ['version', 'descending'] ]
186
- }}
187
- unit_search(id, criteria).collect{|p| p['metadata'].with_indifferent_access}
180
+ and_condition << {:name => name} if name
181
+ and_condition << {:version => version} if version
182
+ and_condition << {:release => release} if release
183
+ and_condition << {:epoch => epoch} if epoch
184
+
185
+ criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type],
186
+ :filters => {
187
+ :unit => {
188
+ '$and' => and_condition
189
+ }
190
+ },
191
+ :sort => {
192
+ :unit => [['name', 'ascending'], ['version', 'descending']]
193
+ }}
194
+ unit_search(id, criteria).map { |p| p['metadata'].with_indifferent_access }
188
195
  end
189
196
 
190
197
  # Retrieves the errata IDs for a single repository
@@ -192,10 +199,10 @@ module Runcible
192
199
  # @param [String] id the ID of the repository
193
200
  # @return [RestClient::Response] the set of repository errata IDs
194
201
  def errata_ids(id)
195
- criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type],
196
- :fields=>{:unit=>[], :association=>['unit_id']}}
202
+ criteria = {:type_ids => [Runcible::Extensions::Errata.content_type],
203
+ :fields => {:unit => [], :association => ['unit_id']}}
197
204
 
198
- unit_search(id, criteria).collect{|i| i['unit_id']}
205
+ unit_search(id, criteria).map { |i| i['unit_id'] }
199
206
  end
200
207
 
201
208
  # Retrieves the errata for a single repository
@@ -203,8 +210,8 @@ module Runcible
203
210
  # @param [String] id the ID of the repository
204
211
  # @return [RestClient::Response] the set of repository errata
205
212
  def errata(id)
206
- criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type]}
207
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
213
+ criteria = {:type_ids => [Runcible::Extensions::Errata.content_type]}
214
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
208
215
  end
209
216
 
210
217
  # Retrieves the distributions for a single repository
@@ -212,9 +219,9 @@ module Runcible
212
219
  # @param [String] id the ID of the repository
213
220
  # @return [RestClient::Response] the set of repository distributions
214
221
  def distributions(id)
215
- criteria = {:type_ids=>[Runcible::Extensions::Distribution.content_type]}
222
+ criteria = {:type_ids => [Runcible::Extensions::Distribution.content_type]}
216
223
 
217
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
224
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
218
225
  end
219
226
 
220
227
  # Retrieves the package groups for a single repository
@@ -222,9 +229,9 @@ module Runcible
222
229
  # @param [String] id the ID of the repository
223
230
  # @return [RestClient::Response] the set of repository package groups
224
231
  def package_groups(id)
225
- criteria = {:type_ids=>[Runcible::Extensions::PackageGroup.content_type]}
232
+ criteria = {:type_ids => [Runcible::Extensions::PackageGroup.content_type]}
226
233
 
227
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
234
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
228
235
  end
229
236
 
230
237
  # Retrieves the package group categoriess for a single repository
@@ -232,8 +239,8 @@ module Runcible
232
239
  # @param [String] id the ID of the repository
233
240
  # @return [RestClient::Response] the set of repository package group categories
234
241
  def package_categories(id)
235
- criteria = {:type_ids=>[Runcible::Extensions::PackageCategory.content_type]}
236
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
242
+ criteria = {:type_ids => [Runcible::Extensions::PackageCategory.content_type]}
243
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
237
244
  end
238
245
 
239
246
  # Retrieves the puppet module IDs for a single repository
@@ -241,10 +248,10 @@ module Runcible
241
248
  # @param [String] id the ID of the repository
242
249
  # @return [RestClient::Response] the set of repository puppet module IDs
243
250
  def puppet_module_ids(id)
244
- criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type],
245
- :fields=>{:unit=>[], :association=>['unit_id']}}
251
+ criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type],
252
+ :fields => {:unit => [], :association => ['unit_id']}}
246
253
 
247
- unit_search(id, criteria).collect{|i| i['unit_id']}
254
+ unit_search(id, criteria).map { |i| i['unit_id'] }
248
255
  end
249
256
 
250
257
  # Retrieves the puppet modules for a single repository
@@ -252,8 +259,8 @@ module Runcible
252
259
  # @param [String] id the ID of the repository
253
260
  # @return [RestClient::Response] the set of repository puppet modules
254
261
  def puppet_modules(id)
255
- criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type]}
256
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
262
+ criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type]}
263
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
257
264
  end
258
265
 
259
266
  # Retrieves the docker image IDs for a single repository
@@ -261,10 +268,10 @@ module Runcible
261
268
  # @param [String] id the ID of the repository
262
269
  # @return [RestClient::Response] the set of repository docker image IDs
263
270
  def docker_image_ids(id)
264
- criteria = {:type_ids=>[Runcible::Extensions::DockerImage.content_type],
265
- :fields=>{:unit=>[], :association=>['unit_id']}}
271
+ criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type],
272
+ :fields => {:unit => [], :association => ['unit_id']}}
266
273
 
267
- unit_search(id, criteria).collect{|i| i['unit_id']}
274
+ unit_search(id, criteria).map { |i| i['unit_id'] }
268
275
  end
269
276
 
270
277
  # Retrieves the docker images for a single repository
@@ -272,8 +279,17 @@ module Runcible
272
279
  # @param [String] id the ID of the repository
273
280
  # @return [RestClient::Response] the set of repository docker images
274
281
  def docker_images(id)
275
- criteria = {:type_ids=>[Runcible::Extensions::DockerImage.content_type]}
276
- unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access}
282
+ criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type]}
283
+ unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
284
+ end
285
+
286
+ # Updates the docker tags in a repo
287
+ # @param [String] id the ID of the repository
288
+ # @param [Hash] tags for an image in the following format
289
+ # the [{:image_id => <image hash>, :tag =>"value"}]
290
+ # @return [RestClient::Response]
291
+ def update_docker_tags(id, tags)
292
+ update(id, :scratchpad => {:tags => tags})
277
293
  end
278
294
 
279
295
  # Creates or updates a sync schedule for a repository
@@ -287,7 +303,8 @@ module Runcible
287
303
  if schedules.empty?
288
304
  Runcible::Resources::RepositorySchedule.new(self.config).create(repo_id, type, schedule)
289
305
  else
290
- Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type, schedules[0]['_id'], {:schedule=>schedule})
306
+ Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type,
307
+ schedules[0]['_id'], :schedule => schedule)
291
308
  end
292
309
  end
293
310
 
@@ -320,7 +337,7 @@ module Runcible
320
337
  # @param [String] repo_id the ID of the repository
321
338
  # @return [RestClient::Response] the repository with full details
322
339
  def retrieve_with_details(repo_id)
323
- retrieve(repo_id, {:details => true})
340
+ retrieve(repo_id, :details => true)
324
341
  end
325
342
 
326
343
  # Regenerate the applicability for consumers bound to a given set of repositories
@@ -333,7 +350,6 @@ module Runcible
333
350
  }
334
351
  regenerate_applicability(criteria)
335
352
  end
336
-
337
353
  end
338
354
  end
339
355
  end
@@ -21,28 +21,26 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class Rpm < Runcible::Extensions::Unit
28
-
29
27
  def self.content_type
30
28
  'rpm'
31
29
  end
32
30
 
33
31
  # This function is not implemented for RPMs since they do not have content IDs
34
32
  def find
35
- raise NotImplementedError
33
+ fail NotImplementedError
36
34
  end
37
35
 
38
36
  # This function is not implemented for RPMs since they do not have content IDs
39
37
  def find_all
40
- raise NotImplementedError
38
+ fail NotImplementedError
41
39
  end
42
40
 
43
41
  # This function is not implemented for RPMs since they do not have content IDs
44
42
  def unassociate_ids_from_repo(repo_id, ids)
45
- raise NotImplementedError
43
+ fail NotImplementedError
46
44
  end
47
45
  end
48
46
  end
@@ -21,14 +21,12 @@
21
21
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
-
25
24
  module Runcible
26
25
  module Extensions
27
26
  class Unit < Runcible::Resources::Unit
28
-
29
27
  # The content type (e.g. rpm, errata)
30
28
  def self.content_type
31
- raise "Content type not defined"
29
+ fail 'Content type not defined'
32
30
  end
33
31
 
34
32
  def content_type
@@ -46,7 +44,7 @@ module Runcible
46
44
  #
47
45
  # @param [Array] id the content ID of the content to retrieve
48
46
  # @return [RestClient::Response] the requested content
49
- def find(id, optional={})
47
+ def find(id, optional = {})
50
48
  optional[:include_repos] ||= true
51
49
  find_all([id], optional).first
52
50
  end
@@ -55,16 +53,16 @@ module Runcible
55
53
  #
56
54
  # @param [Array] ids list of content IDs to retrieve
57
55
  # @return [RestClient::Response] list of content
58
- def find_all(ids, optional={})
56
+ def find_all(ids, optional = {})
59
57
  optional[:include_repos] ||= true
60
- search(content_type, { :filters => {'id'=> {'$in'=> ids}} }, optional)
58
+ search(content_type, { :filters => {'id' => {'$in' => ids}} }, optional)
61
59
  end
62
60
 
63
61
  # Retrieves a single content by it's unit ID
64
62
  #
65
63
  # @param [Array] id the unit ID of the content to retrieve
66
64
  # @return [RestClient::Response] the requested content
67
- def find_by_unit_id(id, optional={})
65
+ def find_by_unit_id(id, optional = {})
68
66
  optional[:include_repos] ||= true
69
67
  find_all_by_unit_ids([id], [], optional).first
70
68
  end
@@ -74,9 +72,9 @@ module Runcible
74
72
  # @param [Array] ids list of content unit IDs to retrieve
75
73
  # @param [Array] fields optional list of to retrieve
76
74
  # @return [RestClient::Response] list of content
77
- def find_all_by_unit_ids(ids, fields=[], optional={})
75
+ def find_all_by_unit_ids(ids, fields = [], optional = {})
78
76
  optional[:include_repos] ||= true
79
- criteria = { :filters => { :_id => { '$in'=> ids } } }
77
+ criteria = { :filters => { :_id => { '$in' => ids } } }
80
78
  criteria[:fields] = fields unless fields.empty?
81
79
  search(content_type, criteria, optional)
82
80
  end
@@ -108,7 +106,7 @@ module Runcible
108
106
  #
109
107
  # @param [String] repo_id the repository ID to remove units from
110
108
  # @param [Array] ids list of the unique hash ids of the content unit
111
- # with respect to this repo. unit_id, _id are other names for this.
109
+ # with respect to this repo. unit_id, id are other names for this.
112
110
  # for example: "efdd2d63-b275-4728-a298-f68cf4c174e7"
113
111
  #
114
112
  # @return [RestClient::Response] a task representing the unit unassociate operation
@@ -122,14 +120,14 @@ module Runcible
122
120
  # @param [String] destination_repo_id the destination repository ID
123
121
  # @param [Hash] optional container for all optional parameters
124
122
  # @return [RestClient::Response] a task representing the unit copy operation
125
- def copy(source_repo_id, destination_repo_id, optional={})
123
+ def copy(source_repo_id, destination_repo_id, optional = {})
126
124
  criteria = {:type_ids => [content_type], :filters => {}}
127
125
  criteria[:filters]['association'] = {'unit_id' => {'$in' => optional[:ids]}} if optional[:ids]
128
126
  criteria[:filters] = optional[:filters] if optional[:filters]
129
127
  criteria[:fields] = {:unit => optional[:fields]} if optional[:fields]
130
128
 
131
129
  payload = {:criteria => criteria}
132
- payload[:override_config] = optional[:override_config] if optional.has_key?(:override_config)
130
+ payload[:override_config] = optional[:override_config] if optional.key?(:override_config)
133
131
 
134
132
  if optional[:copy_children]
135
133
  payload[:override_config] ||= {}
@@ -138,7 +136,6 @@ module Runcible
138
136
 
139
137
  Runcible::Extensions::Repository.new(self.config).unit_copy(destination_repo_id, source_repo_id, payload)
140
138
  end
141
-
142
139
  end
143
140
  end
144
141
  end