Sha256: cd56bedc1155ac0746e4abd441d321485367b484c82b54df613cac733a9c7d9a

Contents?: true

Size: 1.45 KB

Versions: 99

Compression:

Stored size: 1.45 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!(subscription_attributes.except!(*exceptions))
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
katello-3.18.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-3.17.0.rc2.2 app/models/katello/glue/candlepin/subscription.rb
katello-3.17.0.rc2.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.1.2 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.1.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.17.0.rc2 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.17.0.rc1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc5.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc5 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc4.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc4 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc3.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc3 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc2.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc2 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc1.1 app/models/katello/glue/candlepin/subscription.rb
katello-3.16.0.rc1 app/models/katello/glue/candlepin/subscription.rb