summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-15 20:26:40 +0000
committershadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0>2007-02-15 20:26:40 +0000
commit91991f186711251f20e1608815c49d360051c29a (patch)
tree0a0fab9db459b2d03f2dce89bcf15121d28a7b74
parent0b5600a6b49400551b01cec7aa3286d42e45d36c (diff)
downloadpuppet-91991f186711251f20e1608815c49d360051c29a.tar.gz
puppet-91991f186711251f20e1608815c49d360051c29a.tar.xz
puppet-91991f186711251f20e1608815c49d360051c29a.zip
Merge fact_names & fact_values, and param_names & param_values.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2191 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/feature/rails.rb2
-rw-r--r--lib/puppet/parser/resource.rb2
-rw-r--r--lib/puppet/rails.rb2
-rw-r--r--lib/puppet/rails/external/tagging/acts_as_taggable.rb2
-rw-r--r--lib/puppet/rails/fact.rb3
-rw-r--r--lib/puppet/rails/fact_name.rb5
-rw-r--r--lib/puppet/rails/fact_value.rb5
-rw-r--r--lib/puppet/rails/host.rb20
-rw-r--r--lib/puppet/rails/param.rb (renamed from lib/puppet/rails/param_name.rb)6
-rw-r--r--lib/puppet/rails/param_value.rb5
-rw-r--r--lib/puppet/rails/resource.rb27
-rwxr-xr-xtest/language/ast.rb2
-rwxr-xr-xtest/language/interpreter.rb4
-rwxr-xr-xtest/language/resource.rb9
-rwxr-xr-xtest/rails/host.rb28
-rwxr-xr-xtest/rails/railsparameter.rb8
-rwxr-xr-xtest/rails/railsresource.rb7
17 files changed, 55 insertions, 82 deletions
diff --git a/lib/puppet/feature/rails.rb b/lib/puppet/feature/rails.rb
index 1775339a0..edfeccace 100644
--- a/lib/puppet/feature/rails.rb
+++ b/lib/puppet/feature/rails.rb
@@ -28,7 +28,7 @@ Puppet.features.add(:rails) do
unless defined? ActiveRecord
begin
require 'rubygems'
- require_gem 'rails'
+ gem 'rails'
rescue LoadError
# Nothing
end
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 31d43bd18..d10bf5407 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -287,6 +287,8 @@ class Puppet::Parser::Resource
obj.collection_merge(:param_names, @params) do |name, param|
param.to_rails(obj)
end
+
+ obj.save
return obj
end
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 28f2b8584..a582dcef9 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -12,7 +12,7 @@ module Puppet::Rails
:desc => "The database cache for client configurations. Used for
querying within the language."
},
- :dbadapter => [ "sqlite3", "The type of database to use." ],
+ :dbadapter => [ "mysql", "The type of database to use." ],
:dbmigrate => [ false, "Whether to automatically migrate the database." ],
:dbname => [ "puppet", "The name of the database to use." ],
:dbserver => [ "localhost", "The database server for Client caching. Only
diff --git a/lib/puppet/rails/external/tagging/acts_as_taggable.rb b/lib/puppet/rails/external/tagging/acts_as_taggable.rb
index 137a1c2a8..7fd7f6b12 100644
--- a/lib/puppet/rails/external/tagging/acts_as_taggable.rb
+++ b/lib/puppet/rails/external/tagging/acts_as_taggable.rb
@@ -14,7 +14,7 @@ module ActiveRecord
class_inheritable_reader :acts_as_taggable_options
- has_many :taggings, :as => :taggable, :dependent => true
+ has_many :taggings, :as => :taggable, :dependent => :destroy
has_many :tags, :through => :taggings
include ActiveRecord::Acts::Taggable::InstanceMethods
diff --git a/lib/puppet/rails/fact.rb b/lib/puppet/rails/fact.rb
new file mode 100644
index 000000000..ba8462c23
--- /dev/null
+++ b/lib/puppet/rails/fact.rb
@@ -0,0 +1,3 @@
+class Puppet::Rails::Fact < ActiveRecord::Base
+end
+
diff --git a/lib/puppet/rails/fact_name.rb b/lib/puppet/rails/fact_name.rb
deleted file mode 100644
index 47687589d..000000000
--- a/lib/puppet/rails/fact_name.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class Puppet::Rails::FactName < ActiveRecord::Base
- has_many :fact_values, :dependent => :destroy
-end
-
-# $Id$
diff --git a/lib/puppet/rails/fact_value.rb b/lib/puppet/rails/fact_value.rb
deleted file mode 100644
index f42362c97..000000000
--- a/lib/puppet/rails/fact_value.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class Puppet::Rails::FactValue < ActiveRecord::Base
- belongs_to :fact_name
-end
-
-# $Id$
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index 3efdfa9df..900cda6cc 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -4,12 +4,11 @@ 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
+ has_many :facts, :dependent => :destroy
belongs_to :puppet_classes
has_many :source_files
has_many :resources,
- :include => [ :param_names, :param_values ],
+ :include => [ :params ],
:dependent => :destroy
acts_as_taggable
@@ -63,23 +62,18 @@ class Puppet::Rails::Host < ActiveRecord::Base
# Return the value of a fact.
def fact(name)
- if fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'")
- return fv.value
+ if f = self.facts.find_by_name(name)
+ return f.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)
+ collection_merge(:facts, facts) do |name, value|
+ f = facts.find_by_name(name) || facts.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]
-
- fn
+ f
end
end
diff --git a/lib/puppet/rails/param_name.rb b/lib/puppet/rails/param.rb
index c90765ebb..2e98bd258 100644
--- a/lib/puppet/rails/param_name.rb
+++ b/lib/puppet/rails/param.rb
@@ -1,15 +1,14 @@
require 'puppet/util/rails/collection_merger'
-class Puppet::Rails::ParamName < ActiveRecord::Base
+class Puppet::Rails::Param < ActiveRecord::Base
include Puppet::Util::CollectionMerger
- has_many :param_values, :dependent => :destroy
belongs_to :resource
def to_resourceparam(source)
hash = {}
hash[:name] = self.name.to_sym
hash[:source] = source
- hash[:value] = self.param_values.find(:all).collect { |v| v.value }
+ hash[:value] = self.param.value.find(:all).collect { |v| v.value }
if hash[:value].length == 1
hash[:value] = hash[:value].shift
end
@@ -20,4 +19,3 @@ class Puppet::Rails::ParamName < ActiveRecord::Base
end
end
-# $Id$
diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb
deleted file mode 100644
index d988559af..000000000
--- a/lib/puppet/rails/param_value.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-class Puppet::Rails::ParamValue < ActiveRecord::Base
- belongs_to :param_name
-end
-
-# $Id$
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index 6656c2450..b0bfc1ed6 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -1,17 +1,21 @@
require 'puppet'
require 'puppet/rails/external/tagging/init'
-require 'puppet/rails/param_name'
+require 'puppet/rails/param'
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 :params, :dependent => :destroy
belongs_to :source_file
belongs_to :host
acts_as_taggable
+
+ Puppet::Type.eachtype do |type|
+ klass = Class.new(Puppet::Rails::Resource)
+ Object.const_set("Puppet%s" % type.name.to_s.capitalize, klass)
+ end
def tags=(tags)
tags.each do |tag|
@@ -28,20 +32,15 @@ class Puppet::Rails::Resource < ActiveRecord::Base
end
def parameter(param)
- if pn = param_names.find_by_name(param)
- if pv = pn.param_values.find(:first)
- return pv.value
- else
- return nil
- end
+ if p = params.find_by_name(param)
+ return p.value
end
end
def parameters
hash = {}
- self.param_values.find(:all).each do |pvalue|
- pname = pvalue.param_name.name
- hash.store(pname, pvalue.value)
+ self.params.find(:all).each do |p|
+ hash.store(p.name, p.value)
end
return hash
end
@@ -70,8 +69,8 @@ class Puppet::Rails::Resource < ActiveRecord::Base
hash[:scope] = scope
hash[:source] = scope.source
obj = Puppet::Parser::Resource.new(hash)
- self.param_names.each do |pname|
- obj.set(pname.to_resourceparam(scope.source))
+ self.params.each do |p|
+ obj.set(p.to_resourceparam(scope.source))
end
# Store the ID, so we can check if we're re-collecting the same resource.
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 2fdba555c..0e4c6c31c 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -469,7 +469,7 @@ class TestAST < Test::Unit::TestCase
end
assert_nothing_raised("Could not find resource") do
retval = Puppet::Rails::Resource.find(:all,
- :include => :param_names,
+ :include => :params,
:conditions => str)
end
diff --git a/test/language/interpreter.rb b/test/language/interpreter.rb
index b74b15734..42c460fca 100755
--- a/test/language/interpreter.rb
+++ b/test/language/interpreter.rb
@@ -923,11 +923,11 @@ class TestInterpreter < Test::Unit::TestCase
assert(res, "Did not get resource from rails")
- param = res.param_names.find_by_name("owner", :include => :param_values)
+ param = res.params.find_by_name("owner")
assert(param, "Did not find owner param")
- pvalue = param.param_values.find_by_value("root")
+ pvalue = param.value
assert_equal("root", pvalue[:value])
end
end
diff --git a/test/language/resource.rb b/test/language/resource.rb
index a464e1791..ebf47e873 100755
--- a/test/language/resource.rb
+++ b/test/language/resource.rb
@@ -395,27 +395,26 @@ class TestResource < Test::Unit::TestCase
# Now make sure we can find it again
assert_nothing_raised do
obj = Puppet::Rails::Resource.find_by_restype_and_title(
- res.type, res.title, :include => :param_names
+ res.type, res.title, :include => :params
)
end
assert_instance_of(Puppet::Rails::Resource, obj)
# Make sure we get the parameters back
- params = options[:params] || [obj.param_names.collect { |p| p.name },
+ params = options[:params] || [obj.params.collect { |p| p.name },
res.to_hash.keys].flatten.collect { |n| n.to_s }.uniq
params.each do |name|
- param = obj.param_names.find_by_name(name)
+ param = obj.params.find_by_name(name)
if res[name]
assert(param, "resource did not keep %s" % name)
else
assert(! param, "resource did not delete %s" % name)
end
if param
- values = param.param_values.collect { |pv| pv.value }
should = res[param.name]
should = [should] unless should.is_a?(Array)
- assert_equal(should, values,
+ assert_equal(should, param.value,
"%s was different" % param.name)
end
end
diff --git a/test/rails/host.rb b/test/rails/host.rb
index 184d536d5..e8b9a1603 100755
--- a/test/rails/host.rb
+++ b/test/rails/host.rb
@@ -153,20 +153,20 @@ class TestRailsHost < Test::Unit::TestCase
# This actually works in real life, but I can't get it to work in testing.
# I expect it's a caching problem.
-# count = 0
-# host.resources.find(:all).find_all { |r| r.title =~ /file2/ }.each do |r|
-# puts "%s => %s" % [r.ref, r.parameters.inspect]
-# assert_equal("notice", r.parameter("loglevel"),
-# "loglevel was not added")
-# case r.restype
-# when "file":
-# assert_equal("fake", r.parameter("owner"), "owner was not modified")
-# when "exec":
-# assert_equal("fake", r.parameter("user"), "user was not modified")
-# else
-# raise "invalid resource type %s" % r.restype
-# end
-# end
+ count = 0
+ host.resources.find(:all).find_all { |r| r.title =~ /file2/ }.each do |r|
+ puts "%s => %s" % [r.ref, r.parameters.inspect]
+ assert_equal("notice", r.parameter("loglevel"),
+ "loglevel was not added")
+ case r.restype
+ when "file":
+ assert_equal("fake", r.parameter("owner"), "owner was not modified")
+ when "exec":
+ assert_equal("fake", r.parameter("user"), "user was not modified")
+ else
+ raise "invalid resource type %s" % r.restype
+ end
+ end
end
else
$stderr.puts "Install Rails for Rails and Caching tests"
diff --git a/test/rails/railsparameter.rb b/test/rails/railsparameter.rb
index 337f4cb3c..2a306890b 100755
--- a/test/rails/railsparameter.rb
+++ b/test/rails/railsparameter.rb
@@ -25,18 +25,12 @@ class TestRailsParameter < Test::Unit::TestCase
# Use array and non-array values, to make sure we get things back in
# the same form.
{"myname" => "myval", "multiple" => %w{one two three}}.each do |name, value|
- param = Puppet::Rails::ParamName.new(:name => name)
+ param = Puppet::Rails::ParamName.new(:name => name, :value => value)
if value.is_a? Array
values = value
else
values = [value]
end
- valueobjects = values.collect do |v|
- obj = Puppet::Rails::ParamValue.new(:value => v)
- assert_nothing_raised do
- param.param_values << obj
- end
- end
assert(param, "Did not create rails parameter")
diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb
index 302dd99fb..f3cdc22a6 100755
--- a/test/rails/railsresource.rb
+++ b/test/rails/railsresource.rb
@@ -36,9 +36,8 @@ class TestRailsResource < Test::Unit::TestCase
# Now add some params
params.each do |param, value|
- pn = resource.param_names.find_or_create_by_name(param)
- pv = pn.param_values.find_or_create_by_value(value)
- resource.param_names << pn
+ pn = resource.params.find_or_create_by_name_and_value(param, value)
+ resource.params << pn
end
host.save
@@ -58,7 +57,7 @@ class TestRailsResource < Test::Unit::TestCase
interp, scope, source = mkclassframing
# Find the new resource and include all it's parameters.
- resource = Puppet::Rails::Resource.find_by_id(resource.id, :include => [ :param_names, :param_values ])
+ resource = Puppet::Rails::Resource.find_by_id(resource.id, :include => [ :params ])
# Now, try to convert our resource to a real resource
res = nil