Class: ShadowFacter::Facts
- Inherits:
-
Object
- Object
- ShadowFacter::Facts
- Defined in:
- lib/shadow_facter/base.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return a fact value by key.
-
#has_fact?(key) ⇒ Boolean
Return a boolean on the availability of a fact.
-
#initialize(namespace, keys) ⇒ Facts
constructor
A new instance of Facts.
-
#keys ⇒ Object
Return an array of all of the constrained fact keys.
-
#reload! ⇒ Object
Reload facts in namespace.
-
#to_hash ⇒ Object
Return a hash of all of the constrained fact keys and values.
-
#to_json ⇒ Object
Return json of all of the constrained fact keys and values.
-
#to_yaml ⇒ Object
Return yaml of all of the constrained fact keys and values.
-
#value(key) ⇒ Object
Return a fact value by key.
Constructor Details
Instance Method Details
#[](key) ⇒ Object
Return a fact value by key. Returns nil if non-existent or not constrained.
16 17 18 |
# File 'lib/shadow_facter/base.rb', line 16 def [](key) value(key) end |
#has_fact?(key) ⇒ Boolean
Return a boolean on the availability of a fact.
32 33 34 |
# File 'lib/shadow_facter/base.rb', line 32 def has_fact?(key) !value(key).nil? end |
#keys ⇒ Object
Return an array of all of the constrained fact keys.
27 28 29 |
# File 'lib/shadow_facter/base.rb', line 27 def keys @keys.uniq.select { |k| !value(k).nil? } end |
#reload! ⇒ Object
Reload facts in namespace.
57 58 59 |
# File 'lib/shadow_facter/base.rb', line 57 def reload! keys.each { |key| Facter[Base.facter_key(@namespace, key)].flush } end |
#to_hash ⇒ Object
Return a hash of all of the constrained fact keys and values.
37 38 39 40 41 42 |
# File 'lib/shadow_facter/base.rb', line 37 def to_hash keys.inject({}) do |h, k| h[k] = value(k) h end end |
#to_json ⇒ Object
Return json of all of the constrained fact keys and values.
51 52 53 54 |
# File 'lib/shadow_facter/base.rb', line 51 def to_json require 'json' JSON.pretty_generate to_hash end |
#to_yaml ⇒ Object
Return yaml of all of the constrained fact keys and values.
45 46 47 48 |
# File 'lib/shadow_facter/base.rb', line 45 def to_yaml require 'yaml' to_hash.to_yaml end |
#value(key) ⇒ Object
Return a fact value by key. Returns nil if non-existent or not constrained.
21 22 23 24 |
# File 'lib/shadow_facter/base.rb', line 21 def value(key) f = Facter[Base.facter_key(@namespace, key)] f.value unless f.nil? end |