summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-07 16:42:53 -0800
committerNick Lewis <nick@puppetlabs.com>2011-03-08 15:42:27 -0800
commitf83636698229241b2ab35849437f3e515f6ac5c1 (patch)
tree1973c4fe7178f3330151ba59c80ec63089d9f314 /lib/puppet/rails
parent8ce30c83ddba87ba7e2622a46f27143159132789 (diff)
downloadpuppet-f83636698229241b2ab35849437f3e515f6ac5c1.tar.gz
puppet-f83636698229241b2ab35849437f3e515f6ac5c1.tar.xz
puppet-f83636698229241b2ab35849437f3e515f6ac5c1.zip
(#6338) Implement search for InventoryActiveRecord facts terminus
Paired-With: Max Martin Reviewed-By: Jacob Helwig
Diffstat (limited to 'lib/puppet/rails')
-rw-r--r--lib/puppet/rails/inventory_host.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/puppet/rails/inventory_host.rb b/lib/puppet/rails/inventory_host.rb
index 433e54389..10dd62083 100644
--- a/lib/puppet/rails/inventory_host.rb
+++ b/lib/puppet/rails/inventory_host.rb
@@ -3,6 +3,32 @@ require 'puppet/rails/inventory_fact'
class Puppet::Rails::InventoryHost < ::ActiveRecord::Base
has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :dependent => :delete_all
+ named_scope :has_fact_with_value, lambda { |name,value|
+ {
+ :conditions => ["inventory_facts.name = ? AND inventory_facts.value = ?", name, value],
+ :joins => :facts
+ }
+ }
+
+ named_scope :has_fact_without_value, lambda { |name,value|
+ {
+ :conditions => ["inventory_facts.name = ? AND inventory_facts.value != ?", name, value],
+ :joins => :facts
+ }
+ }
+
+ named_scope :has_fact, lambda { |name|
+ {
+ :conditions => ["inventory_facts.name = ?", name],
+ :joins => :facts
+ }
+ }
+
+ def value_for(fact_name)
+ fact = facts.find_by_name(fact_name)
+ fact ? fact.value : nil
+ end
+
def facts_to_hash
facts.inject({}) do |fact_hash,fact|
fact_hash.merge(fact.name => fact.value)