diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 04:57:57 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 04:57:57 +0000 |
commit | 9f4870637ce57d548d23c0b3330200014327c268 (patch) | |
tree | b820cfb5a8150dc00d475ffe0cde6316ad210a91 /lib/puppet/rails | |
parent | dc5f4dc0d01dc2ccb4679afbf3802a7ab0f3c126 (diff) | |
download | puppet-9f4870637ce57d548d23c0b3330200014327c268.tar.gz puppet-9f4870637ce57d548d23c0b3330200014327c268.tar.xz puppet-9f4870637ce57d548d23c0b3330200014327c268.zip |
All rails *and* language tests now pass, with the exception of a language/resource test that passes by itself but fails when run as part of the whole suite. Also, I added deletion where appropriate, so that unspecified resources, parameters, and facts are now deleted, as one would expect.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1951 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r-- | lib/puppet/rails/host.rb | 74 | ||||
-rw-r--r-- | lib/puppet/rails/param_name.rb | 3 | ||||
-rw-r--r-- | lib/puppet/rails/resource.rb | 3 |
3 files changed, 40 insertions, 40 deletions
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index a46fa92a5..fcd078cb7 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -1,6 +1,9 @@ require 'puppet/rails/resource' +require 'puppet/util/rails/collection_merger' class Puppet::Rails::Host < ActiveRecord::Base + include Puppet::Util::CollectionMerger + has_many :fact_values, :through => :fact_names has_many :fact_names, :dependent => :destroy belongs_to :puppet_classes @@ -11,14 +14,6 @@ class Puppet::Rails::Host < ActiveRecord::Base acts_as_taggable - def facts(name) - if fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'") - return fv.value - else - return nil - end - end - # If the host already exists, get rid of its objects def self.clean(host) if obj = self.find_by_name(host) @@ -31,60 +26,59 @@ class Puppet::Rails::Host < ActiveRecord::Base # Store our host in the database. def self.store(hash) - unless hash[:name] + unless name = hash[:name] raise ArgumentError, "You must specify the hostname for storage" end args = {} - if hash[:facts].include?("ipaddress") - args[:ip] = hash[:facts]["ipaddress"] + unless host = find_by_name(name) + host = new(:name => name) end - unless host = find_by_name(hash[:facts]["hostname"]) - host = new(:name => hash[:facts]["hostname"]) + if ip = hash[:facts]["ipaddress"] + host.ip = ip end - # Store the facts into the - hash[:facts].each do |name, value| - fn = host.fact_names.find_by_name(name) || host.fact_names.build(:name => name) - unless fn.fact_values.find_by_value(value) - fn.fact_values.build(:value => value) - end - end + # Store the facts into the database. + host.setfacts(hash[:facts]) unless hash[:resources] raise ArgumentError, "You must pass resources" end - resources = [] - hash[:resources].each do |resource| - resources << resource.to_rails(host) - end + host.setresources(hash[:resources]) host.save return host end - # Add all of our RailsObjects - def addobjects(objects) - objects.each do |tobj| - params = {} - tobj.each do |p,v| params[p] = v end - - args = {:ptype => tobj.type, :name => tobj.name} - [:tags, :file, :line].each do |param| - if val = tobj.send(param) - args[param] = val - end + # Return the value of a fact. + def fact(name) + if fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'") + return fv.value + else + return nil + end + end + + def setfacts(facts) + collection_merge(:fact_names, facts) do |name, value| + fn = fact_names.find_by_name(name) || fact_names.build(:name => name) + # We're only ever going to have one fact value, at this point. + unless fv = fn.fact_values.find_by_value(value) + fv = fn.fact_values.build(:value => value) end + fn.fact_values = [fv] - robj = rails_objects.build(args) + fn + end + end - robj.addparams(params) - if tobj.collectable - robj.toggle(:collectable) - end + # Set our resources. + def setresources(list) + collection_merge(:resources, list) do |resource| + resource.to_rails(self) end end end diff --git a/lib/puppet/rails/param_name.rb b/lib/puppet/rails/param_name.rb index dba6960da..b609f10c5 100644 --- a/lib/puppet/rails/param_name.rb +++ b/lib/puppet/rails/param_name.rb @@ -1,4 +1,7 @@ +require 'puppet/util/rails/collection_merger' + class Puppet::Rails::ParamName < ActiveRecord::Base + include Puppet::Util::CollectionMerger has_many :param_values, :dependent => :destroy belongs_to :resource diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index c0a7fbd8c..d78b02b88 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -1,8 +1,11 @@ require 'puppet' require 'puppet/rails/lib/init' require 'puppet/rails/param_name' +require 'puppet/util/rails/collection_merger' class Puppet::Rails::Resource < ActiveRecord::Base + include Puppet::Util::CollectionMerger + has_many :param_values, :through => :param_names has_many :param_names, :dependent => :destroy has_many :source_files |