diff options
author | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-14 23:20:26 +0000 |
---|---|---|
committer | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-14 23:20:26 +0000 |
commit | 8714e14c10492361cac62726a3c1abe44d9ec23f (patch) | |
tree | 007d3d0e5351222a4f49a3d6827b352c1421a538 /lib/puppet/rails/resource.rb | |
parent | 026ec4f3996655f01b85b03c6db79c9e15d035c5 (diff) | |
download | puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.tar.gz puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.tar.xz puppet-8714e14c10492361cac62726a3c1abe44d9ec23f.zip |
New rails stuff redux.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1925 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/rails/resource.rb')
-rw-r--r-- | lib/puppet/rails/resource.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb new file mode 100644 index 000000000..7cf6f6852 --- /dev/null +++ b/lib/puppet/rails/resource.rb @@ -0,0 +1,50 @@ +require 'puppet' +require 'puppet/rails/lib/init' +require 'puppet/rails/param_name' + +class Puppet::Rails::Resource < ActiveRecord::Base + has_many :param_values, :through => :param_names + has_many :param_names + has_many :source_files + belongs_to :hosts + + 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| + pname = self.param_names.find(:first) + hash.store(pname.name.to_sym, pvalue.value) + end + return hash + end + + # Convert our object to a resource. Do not retain whether the object + # is collectable, though, since that would cause it to get stripped + # from the configuration. + def to_resource(scope) + hash = self.attributes + hash.delete("type") + 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) + self.param_names.each do |pname| + obj.set(pname.to_resourceparam(scope.source)) + end + + return obj + end +end |