[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:01 UTC 2009


The following commit has been merged in the master branch:
commit b7ab54c7f094c34b9f80224a63521a2873d7c1c1
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Sun Jan 25 20:50:28 2009 +0100

    Add methods to return hash instead of objects to params and tags
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/rails/param_value.rb b/lib/puppet/rails/param_value.rb
index fc00a43..483e4d2 100644
--- a/lib/puppet/rails/param_value.rb
+++ b/lib/puppet/rails/param_value.rb
@@ -1,28 +1,47 @@
+require 'puppet/util/rails/reference_serializer'
+
 class Puppet::Rails::ParamValue < ActiveRecord::Base
+    include Puppet::Util::ReferenceSerializer
+    extend Puppet::Util::ReferenceSerializer
+
     belongs_to :param_name
     belongs_to :resource
 
     def value
-        val = self[:value]
-        if val =~ /^--- \!/
-            YAML.load(val)
-        else
-            val
-        end
+        unserialize_value(self[:value])
     end
 
     # I could not find a cleaner way to handle making sure that resource references
     # were consistently serialized and deserialized.
     def value=(val)
-        if val.is_a?(Puppet::Parser::Resource::Reference)
-            self[:value] = YAML.dump(val)
-        else
-            self[:value] = val
-        end
+        self[:value] = serialize_value(val)
     end
 
     def to_label
       "#{self.param_name.name}"
-    end  
+    end
+
+    # returns an array of hash containing all the parameters of a given resource
+    def self.find_all_params_from_resource(db_resource)
+        params = db_resource.connection.select_all("SELECT v.id, v.value, v.line, v.resource_id, v.param_name_id, n.name FROM param_values as v INNER JOIN param_names as n ON v.param_name_id=n.id WHERE v.resource_id=%s" % db_resource.id)
+        params.each do |val|
+            val['value'] = unserialize_value(val['value'])
+            val['line'] = val['line'] ? Integer(val['line']) : nil
+            val['resource_id'] = Integer(val['resource_id'])
+        end
+        params
+    end
+
+    # returns an array of hash containing all the parameters of a given host
+    def self.find_all_params_from_host(db_host)
+        params = db_host.connection.select_all("SELECT v.id, v.value,  v.line, v.resource_id, v.param_name_id, n.name FROM param_values as v INNER JOIN resources r ON v.resource_id=r.id INNER JOIN param_names as n ON v.param_name_id=n.id WHERE r.host_id=%s" % db_host.id)
+        params.each do |val|
+            val['value'] = unserialize_value(val['value'])
+            val['line'] = val['line'] ? Integer(val['line']) : nil
+            val['resource_id'] = Integer(val['resource_id'])
+        end
+        params
+    end
+
 end
 
diff --git a/lib/puppet/rails/resource_tag.rb b/lib/puppet/rails/resource_tag.rb
index f9694e0..57649b9 100644
--- a/lib/puppet/rails/resource_tag.rb
+++ b/lib/puppet/rails/resource_tag.rb
@@ -5,4 +5,22 @@ class Puppet::Rails::ResourceTag < ActiveRecord::Base
     def to_label
       "#{self.puppet_tag.name}"
     end  
+
+    # returns an array of hash containing tags of resource
+    def self.find_all_tags_from_resource(db_resource)
+        tags = db_resource.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags as t INNER JOIN puppet_tags as p ON t.puppet_tag_id=p.id WHERE t.resource_id=%s" % db_resource.id)
+        tags.each do |val|
+            val['resource_id'] = Integer(val['resource_id'])
+        end
+        tags
+    end
+
+    # returns an array of hash containing tags of a host
+    def self.find_all_tags_from_host(db_host)
+        tags = db_host.connection.select_all("SELECT t.id, t.resource_id, p.name FROM resource_tags as t INNER JOIN resources r ON t.resource_id=r.id INNER JOIN puppet_tags as p ON t.puppet_tag_id=p.id WHERE r.host_id=%s" % db_host.id)
+        tags.each do |val|
+            val['resource_id'] = Integer(val['resource_id'])
+        end
+        tags
+    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list