Sha256: 3b3fa676491ee9bd0585c1efa870038ea5af398b03a4c99026a0311e67d025b0
Contents?: true
Size: 1.46 KB
Versions: 54
Compression:
Stored size: 1.46 KB
Contents
module Katello module Glue::Candlepin::Subscription def self.included(base) base.send :include, LazyAccessor base.send :include, InstanceMethods base.send :extend, ClassMethods base.class_eval do lazy_accessor :backend_data, :initializer => lambda { |_s| self.class.candlepin_data(self.organization.label, self.cp_id) } end end module ClassMethods def candlepin_data(org, cp_id) Katello::Resources::Candlepin::Product.get(org, cp_id)[0] end def get_for_owner(organization) Katello::Resources::Candlepin::Product.all(organization).select do |product| #this product's id is non-numeric (marketing product), or its a custom product !Glue::Candlepin::Product.engineering_product_id?(product['id']) || Katello::Product.find_by(:cp_id => product['id']).try(:custom?) end end end module InstanceMethods def import_data subscription_attributes = {} product_json = self.backend_data product_json["attributes"].each { |attr| subscription_attributes[attr["name"].to_sym] = attr["value"] } subscription_attributes[:name] = product_json["name"] subscription_attributes[:instance_multiplier] = product_json["multiplier"] exceptions = subscription_attributes.keys.map(&:to_sym) - self.attribute_names.map(&:to_sym) self.update_attributes!(subscription_attributes.except!(*exceptions)) end end end end
Version data entries
54 entries across 54 versions & 1 rubygems