Sha256: 652b77be2e7f968aaa77e4065f2b2d9341c8dfaf7a87614c36dd268fc85b0e33
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 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 product['id'].to_i.to_s != 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
katello-3.7.0.rc1 | app/models/katello/glue/candlepin/subscription.rb |