Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

860952 - do not call with_indifferent_access on Array #840

Merged
merged 1 commit into from Oct 12, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/lib/resources/candlepin.rb
Expand Up @@ -10,6 +10,8 @@
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'util/data'

module Resources

module Candlepin
Expand Down Expand Up @@ -146,7 +148,7 @@ def regenerate_identity_certificates uuid

def entitlements uuid
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'entitlements'), self.default_headers).body
JSON.parse(response).collect { |e| e.with_indifferent_access }
Util::Data::array_with_indifferent_access JSON.parse(response)
end

def consume_entitlement uuid, pool, quantity = nil
Expand All @@ -172,7 +174,7 @@ def remove_certificate uuid, serial_id

def guests uuid
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'guests'), self.default_headers).body
JSON.parse(response).map { |e| e.with_indifferent_access }
Util::Data::array_with_indifferent_access JSON.parse(response)
rescue => e
return []
end
Expand Down Expand Up @@ -200,7 +202,7 @@ def compliance uuid
def events uuid
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'events'), self.default_headers).body
unless response.empty?
JSON.parse(response).collect {|s| s.with_indifferent_access}
Util::Data::array_with_indifferent_access JSON.parse(response)
else
return []
end
Expand Down Expand Up @@ -272,7 +274,7 @@ def destroy_imports organization_name

def imports organization_name
imports_json = self.get(join_path(path(organization_name), 'imports'), self.default_headers)
JSON.parse(imports_json).collect {|s| s.with_indifferent_access}
Util::Data::array_with_indifferent_access JSON.parse(imports_json)
end

def pools key, filter = {}
Expand All @@ -281,12 +283,12 @@ def pools key, filter = {}
else
jsonStr = self.get(join_path('candlepin', 'pools') + hash_to_query(filter), self.default_headers).body
end
JSON.parse(jsonStr).collect {|p| p.with_indifferent_access }
Util::Data::array_with_indifferent_access JSON.parse(jsonStr)
end

def statistics key
jsonStr = self.get(join_path(path(key), 'statistics'), self.default_headers).body
JSON.parse(jsonStr).collect {|p| p.with_indifferent_access }
Util::Data::array_with_indifferent_access JSON.parse(jsonStr)
end

def generate_ueber_cert key
Expand All @@ -308,7 +310,7 @@ def get_ueber_cert_pkcs12 key, name = nil, password = nil

def events key
response = self.get(join_path(path(key), 'events'), self.default_headers).body
JSON.parse(response).collect { |e| e.with_indifferent_access }
Util::Data::array_with_indifferent_access JSON.parse(response)
end

def service_levels uuid
Expand Down Expand Up @@ -379,7 +381,7 @@ class Pool < CandlepinResource
class << self
def find pool_id
pool_json = self.get(path(pool_id), self.default_headers).body
JSON.parse(pool_json).with_indifferent_access
Util::Data::array_with_indifferent_access JSON.parse(pool_json)
end

def get_for_owner owner_key
Expand Down Expand Up @@ -506,7 +508,7 @@ def get id=nil
products_json = super(path(id), self.default_headers).body
products = JSON.parse(products_json)
products = [products] unless id.nil?
products.collect {|p| p.with_indifferent_access }
Util::Data::array_with_indifferent_access products
end


Expand Down
21 changes: 21 additions & 0 deletions src/lib/util/data.rb
@@ -0,0 +1,21 @@
#
# Copyright 2012 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Util
module Data

def self.array_with_indifferent_access variable
variable.map { |x| x.with_indifferent_access }
end

end
end