Module: Glue::Candlepin::CandlepinObject::ClassMethods
- Defined in:
- app/models/katello/glue/candlepin/candlepin_object.rb
Instance Method Summary collapse
- #get_candlepin_ids(organization) ⇒ Object
- #get_for_organization(organization) ⇒ Object
- #import_all ⇒ Object
- #import_candlepin_ids(organization) ⇒ Object
- #with_identifier(ids) ⇒ Object
- #with_identifiers(ids) ⇒ Object
Instance Method Details
#get_candlepin_ids(organization) ⇒ Object
12 13 14 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 12 def get_candlepin_ids(organization) self.get_for_owner(organization).map { |subscription| subscription["id"] } end |
#get_for_organization(organization) ⇒ Object
6 7 8 9 10 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 6 def get_for_organization(organization) # returns objects from AR database rather than candlepin data pool_ids = self.get_for_owner(organization.label).collect { |x| x['id'] } self.where(:cp_id => pool_ids) end |
#import_all ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 34 def import_all candlepin_ids = [] Organization.all.each do |org| import_candlepin_ids(org.label) candlepin_ids.concat(get_candlepin_ids(org.label)) end self.all.each do |item| if candlepin_ids.include?(item.cp_id) item.import_data else item.destroy end end end |
#import_candlepin_ids(organization) ⇒ Object
16 17 18 19 20 21 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 16 def import_candlepin_ids(organization) candlepin_ids = self.get_candlepin_ids(organization) candlepin_ids.each do |cp_id| self.where(:cp_id => cp_id).first_or_create unless cp_id.nil? end end |
#with_identifier(ids) ⇒ Object
23 24 25 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 23 def with_identifier(ids) self.with_identifiers(ids).first end |
#with_identifiers(ids) ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/katello/glue/candlepin/candlepin_object.rb', line 27 def with_identifiers(ids) ids = [ids] unless ids.is_a?(Array) ids.map!(&:to_s) id_integers = ids.map { |string| Integer(string) rescue -1 } where("#{self.table_name}.id = (?) or #{self.table_name}.cp_id = (?)", id_integers, ids) end |