summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/resource.rb6
-rw-r--r--lib/puppet/rails/database/schema.rb2
-rw-r--r--lib/puppet/rails/host.rb17
-rw-r--r--lib/puppet/rails/resource.rb10
-rw-r--r--test/lib/puppettest/railstesting.rb2
-rwxr-xr-xtest/rails/railsresource.rb2
6 files changed, 11 insertions, 28 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 0802dd882..7ea85dded 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -266,11 +266,11 @@ class Puppet::Parser::Resource
# 'type' isn't a valid column name, so we have to use something else.
args = symbolize_options(args)
- #args[:type] = args[:type]
- #args.delete(:type)
+ args[:restype] = args[:type]
+ args.delete(:type)
# Let's see if the object exists
- if obj = host.resources.find_by_type_and_title(self.type, self.title)
+ if obj = host.resources.find_by_restype_and_title(self.type, self.title)
# We exist
args.each do |param, value|
obj[param] = value
diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb
index 9151bee46..609d6abdd 100644
--- a/lib/puppet/rails/database/schema.rb
+++ b/lib/puppet/rails/database/schema.rb
@@ -4,7 +4,7 @@ def self.init
ActiveRecord::Schema.define do
create_table :resources do |t|
t.column :title, :string, :null => false
- t.column :type, :string
+ t.column :restype, :string
t.column :host_id, :integer
t.column :source_file_id, :integer
t.column :exported, :boolean
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb
index 55b33621a..fd0642722 100644
--- a/lib/puppet/rails/host.rb
+++ b/lib/puppet/rails/host.rb
@@ -64,26 +64,15 @@ class Puppet::Rails::Host < ActiveRecord::Base
raise ArgumentError, "You must pass resources"
end
- typenames = []
- Puppet::Type.loadall
- Puppet::Type.eachtype do |type|
- typenames << type.name.to_s
- end
-
Puppet::Util.benchmark(:info, "Converted resources") do
hash[:resources].each do |resource|
resargs = resource.to_hash.stringify_keys
-
- if typenames.include?(resource.type)
- rtype = "Puppet#{resource.type.to_s.capitalize}"
- end
-
if create
- res = host.resources.find_or_create_by_type_and_title(rtype, resource[:title])
+ res = host.resources.find_or_create_by_restype_and_title(resource[:type], resource[:title])
else
- unless res = host.resources.find_by_type_and_title(rtype, resource[:title])
- res = host.resources.new(:type => rtype, :title => resource[:title])
+ unless res = host.resources.find_by_restype_and_title(resource[:type], resource[:title])
+ res = host.resources.new(:restype => resource[:type], :title => resource[:title])
host.resources << res
end
end
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index 68a784d9d..423b227ad 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -10,12 +10,6 @@ class Puppet::Rails::Resource < ActiveRecord::Base
acts_as_taggable
- Puppet::Type.loadall
- Puppet::Type.eachtype do |type|
- klass = Class.new(Puppet::Rails::Resource)
- Object.const_set("Puppet%s" % type.name.to_s.capitalize, klass)
- end
-
def parameters
hash = {}
self.param_values.find(:all).each do |pvalue|
@@ -30,14 +24,14 @@ class Puppet::Rails::Resource < ActiveRecord::Base
# from the configuration.
def to_resource(scope)
hash = self.attributes
- hash.delete("type")
+ hash["type"] = hash["restype"]
+ hash.delete("restype")
hash.delete("host_id")
hash.delete("source_file_id")
hash.delete("id")
hash.each do |p, v|
hash.delete(p) if v.nil?
end
- hash[:type] = self.class.to_s.gsub(/Puppet/,'').downcase
hash[:scope] = scope
hash[:source] = scope.source
obj = Puppet::Parser::Resource.new(hash)
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index baac6e03a..1d2d94863 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -22,7 +22,7 @@ module PuppetTest::RailsTesting
# Now build a resource
resources = []
- resources << mkresource(:type => type, :title => title, :exported => true,
+ resources << mkresource(:restype => type, :title => title, :exported => true,
:params => params)
# Now collect our facts
diff --git a/test/rails/railsresource.rb b/test/rails/railsresource.rb
index f16f925a8..36df881ca 100755
--- a/test/rails/railsresource.rb
+++ b/test/rails/railsresource.rb
@@ -24,11 +24,11 @@ class TestRailsResource < Test::Unit::TestCase
# Now build a resource
resource = host.resources.create(
:title => "/tmp/to_resource",
+ :restype => "file",
:exported => true)
# For some reason the child class doesn't exist until after the resource is created.
# Probably an issue with the dynamic class generation.
- resource.type = "PuppetFile"
resource.save
# Now add some params