diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/resource.rb | 20 | ||||
-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 |
6 files changed, 45 insertions, 15 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 05e0af4c1..64c4e1bb9 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -231,13 +231,13 @@ class Puppet::Parser::Resource end end - #def tags - # unless defined? @tags - # @tags = scope.tags - # @tags << self.type - # end - # @tags - #end + def tags + unless defined? @tags + @tags = scope.tags + @tags << self.type + end + @tags + end def to_hash @params.inject({}) do |hash, ary| @@ -250,9 +250,7 @@ class Puppet::Parser::Resource # Turn our parser resource into a Rails resource. def to_rails(host) args = {} - #FIXME: support files/lines, etc. - #%w{type title tags file line exported}.each do |param| - %w{type title exported}.each do |param| + %w{type title tags file line exported}.each do |param| if value = self.send(param) args[param] = value end @@ -317,7 +315,7 @@ class Puppet::Parser::Resource obj.file = self.file obj.line = self.line - #obj.tags = self.tags + obj.tags = self.tags return obj end 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 |