lib/rubix/sender.rb in rubix-0.0.11 vs lib/rubix/sender.rb in rubix-0.0.12

- old
+ new

@@ -107,11 +107,25 @@ # templates will automatically be attached. # # @return [Rubix::Host] def initialize_host self.host = (Host.find(:name => settings['host']) || Host.new(:name => settings['host'])) - host.host_groups = ((host.host_groups || []) + host_groups).flatten.compact.uniq - host.templates = ((host.templates || []) + templates).flatten.compact.uniq + + current_host_group_names = (host.host_groups || []).map(&:name) + current_template_names = (host.templates || []).map(&:name) + + host_groups_to_add, templates_to_add = [], [] + + (self.host_groups || []).each do |hg| + host_groups_to_add << hg unless current_host_group_names.include?(hg.name) + end + + (self.templates || []).each do |t| + templates_to_add << t unless current_template_names.include?(t.name) + end + + host.host_groups = ((host.host_groups || []) + host_groups_to_add).flatten.compact.uniq + host.templates = ((host.templates || []) + templates_to_add).flatten.compact.uniq host.save host end # Find or create the applications for this data.