diff options
author | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 22:04:09 +0000 |
---|---|---|
committer | shadoi <shadoi@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-19 22:04:09 +0000 |
commit | 115ec095357171381e2af3aa5ebbd61164b40064 (patch) | |
tree | 2060872eefd6fdbae72a20cb95998a1d364c8a80 /lib/puppet/rails | |
parent | f851ca64cf3861ffa63cf2698fd4719361803f82 (diff) | |
download | puppet-115ec095357171381e2af3aa5ebbd61164b40064.tar.gz puppet-115ec095357171381e2af3aa5ebbd61164b40064.tar.xz puppet-115ec095357171381e2af3aa5ebbd61164b40064.zip |
Re-add support for tags and file/lines
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1953 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r-- | lib/puppet/rails/host.rb | 6 | ||||
-rw-r--r-- | lib/puppet/rails/lib/acts_as_taggable.rb | 6 | ||||
-rw-r--r-- | lib/puppet/rails/lib/tag.rb | 12 | ||||
-rw-r--r-- | lib/puppet/rails/resource.rb | 12 | ||||
-rw-r--r-- | lib/puppet/rails/source_file.rb | 4 |
5 files changed, 36 insertions, 4 deletions
diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index fcd078cb7..0b88afe62 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -53,6 +53,12 @@ class Puppet::Rails::Host < ActiveRecord::Base return host end + def tags=(tags) + tags.each do |tag| + self.tag_with tag + end + end + # Return the value of a fact. def fact(name) if fv = self.fact_values.find(:first, :conditions => "fact_names.name = '#{name}'") diff --git a/lib/puppet/rails/lib/acts_as_taggable.rb b/lib/puppet/rails/lib/acts_as_taggable.rb index e9bd03696..137a1c2a8 100644 --- a/lib/puppet/rails/lib/acts_as_taggable.rb +++ b/lib/puppet/rails/lib/acts_as_taggable.rb @@ -32,6 +32,10 @@ module ActiveRecord acts_as_taggable_options[:taggable_type], list
])
end
+ def tags(options = {})
+ options.merge!(:taggable_type => self.to_s)
+ Tag.tags(options)
+ end
end
module InstanceMethods
@@ -55,4 +59,4 @@ module ActiveRecord end
end
end
-end
\ No newline at end of file +end
diff --git a/lib/puppet/rails/lib/tag.rb b/lib/puppet/rails/lib/tag.rb index ca31171b2..191abb08c 100644 --- a/lib/puppet/rails/lib/tag.rb +++ b/lib/puppet/rails/lib/tag.rb @@ -1,6 +1,16 @@ class Tag < ActiveRecord::Base has_many :taggings + def self.tags(options = {}) + query = "select tags.id, name, count(*) as count" + query << " from taggings, tags" + query << " where tags.id = tag_id" + query << " group by tag_id" + query << " order by #{options[:order]}" if options[:order] != nil + query << " limit #{options[:limit]}" if options[:limit] != nil + tags = Tag.find_by_sql(query) + end + def self.parse(list) tag_names = [] @@ -37,4 +47,4 @@ class Tag < ActiveRecord::Base def to_s name end -end
\ No newline at end of file +end diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb index 011b9a883..43d7bbf4b 100644 --- a/lib/puppet/rails/resource.rb +++ b/lib/puppet/rails/resource.rb @@ -8,10 +8,20 @@ class Puppet::Rails::Resource < ActiveRecord::Base has_many :param_values, :through => :param_names has_many :param_names, :dependent => :destroy - has_many :source_files + belongs_to :source_file belongs_to :host acts_as_taggable + + def tags=(tags) + tags.each do |tag| + self.tag_with tag + end + end + + def file=(file) + self.source_file = Puppet::Rails::SourceFile.new(:filename => file) + end def [](param) return super || parameter(param) diff --git a/lib/puppet/rails/source_file.rb b/lib/puppet/rails/source_file.rb index d300ec74c..51d1b1fb5 100644 --- a/lib/puppet/rails/source_file.rb +++ b/lib/puppet/rails/source_file.rb @@ -1,3 +1,5 @@ class Puppet::Rails::SourceFile < ActiveRecord::Base - has_many :hosts, :puppet_classes, :resources + has_one :host + has_one :puppet_class + has_one :resource end |