Class: Facter::FactGroups
- Inherits:
-
Object
- Object
- Facter::FactGroups
- Defined in:
- lib/facter/framework/config/fact_groups.rb
Constant Summary collapse
- STRING_TO_SECONDS =
{ 'seconds' => 1, 'minutes' => 60, 'hours' => 3600, 'days' => 3600 * 24 }.freeze
Instance Attribute Summary collapse
- #block_list ⇒ Object readonly
- #facts_ttls ⇒ Object readonly
- #groups ⇒ Object readonly
Instance Method Summary collapse
-
#blocked_facts ⇒ Object
Breakes down blocked groups in blocked facts.
- #get_fact(fact_name) ⇒ Object
-
#get_fact_group(fact_name) ⇒ Object
Get the group name a fact is part of.
-
#get_group_ttls(group_name) ⇒ Object
Get config ttls for a given group.
-
#initialize ⇒ FactGroups
constructor
A new instance of FactGroups.
Constructor Details
#initialize ⇒ FactGroups
Returns a new instance of FactGroups.
13 14 15 16 17 18 19 20 21 |
# File 'lib/facter/framework/config/fact_groups.rb', line 13 def initialize @groups = Facter::Config::FACT_GROUPS.dup load_groups load_facts_ttls # Reverse sort facts so that children have precedence when caching. eg: os.macosx vs os @facts_ttls = @facts_ttls.sort.reverse.to_h end |
Instance Attribute Details
#block_list ⇒ Object (readonly)
7 8 9 |
# File 'lib/facter/framework/config/fact_groups.rb', line 7 def block_list @block_list end |
#facts_ttls ⇒ Object (readonly)
7 8 9 |
# File 'lib/facter/framework/config/fact_groups.rb', line 7 def facts_ttls @facts_ttls end |
#groups ⇒ Object (readonly)
7 8 9 |
# File 'lib/facter/framework/config/fact_groups.rb', line 7 def groups @groups end |
Instance Method Details
#blocked_facts ⇒ Object
Breakes down blocked groups in blocked facts
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/facter/framework/config/fact_groups.rb', line 24 def blocked_facts fact_list = [] @block_list.each do |group_name| facts_for_block = @groups[group_name] fact_list += facts_for_block || [group_name] end fact_list end |
#get_fact(fact_name) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/facter/framework/config/fact_groups.rb', line 51 def get_fact(fact_name) return @facts_ttls[fact_name] if @facts_ttls[fact_name] result = @facts_ttls.select { |name, fact| break fact if fact_name =~ /^#{name}\..*/ } return nil if result == {} result end |
#get_fact_group(fact_name) ⇒ Object
Get the group name a fact is part of
37 38 39 40 41 42 |
# File 'lib/facter/framework/config/fact_groups.rb', line 37 def get_fact_group(fact_name) fact = get_fact(fact_name) return fact[:group] if fact @groups.detect { |k, v| break k if Array(v).find { |f| fact_name =~ /^#{f}.*/ } } end |
#get_group_ttls(group_name) ⇒ Object
Get config ttls for a given group
45 46 47 48 49 |
# File 'lib/facter/framework/config/fact_groups.rb', line 45 def get_group_ttls(group_name) return unless (ttls = @groups_ttls.find { |g| g[group_name] }) ttls_to_seconds(ttls[group_name]) end |