summaryrefslogtreecommitdiffstats
path: root/lib/puppet/rails/inventory_node.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/rails/inventory_node.rb')
-rw-r--r--lib/puppet/rails/inventory_node.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/puppet/rails/inventory_node.rb b/lib/puppet/rails/inventory_node.rb
new file mode 100644
index 000000000..52f8621a4
--- /dev/null
+++ b/lib/puppet/rails/inventory_node.rb
@@ -0,0 +1,25 @@
+require 'puppet/rails/inventory_fact'
+
+class Puppet::Rails::InventoryNode < ::ActiveRecord::Base
+ has_many :facts, :class_name => "Puppet::Rails::InventoryFact", :foreign_key => :node_id, :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
+ }
+ }
+
+ def facts_to_hash
+ facts.inject({}) do |fact_hash,fact|
+ fact_hash.merge(fact.name => fact.value)
+ end
+ end
+end