Class: Facter::FactGroups

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFactGroups

Returns a new instance of FactGroups.



12
13
14
15
16
17
18
19
20
# File 'lib/facter/framework/config/fact_groups.rb', line 12

def initialize
  @groups = Facter::Config::FACT_GROUPS.dup
  load_groups
  load_groups_from_options
  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_listObject (readonly)



8
9
10
# File 'lib/facter/framework/config/fact_groups.rb', line 8

def block_list
  @block_list
end

#facts_ttlsObject (readonly)



8
9
10
# File 'lib/facter/framework/config/fact_groups.rb', line 8

def facts_ttls
  @facts_ttls
end

#groupsObject (readonly)



8
9
10
# File 'lib/facter/framework/config/fact_groups.rb', line 8

def groups
  @groups
end

#groups_ttlsObject



7
8
9
# File 'lib/facter/framework/config/fact_groups.rb', line 7

def groups_ttls
  @groups_ttls
end

Instance Method Details

#blocked_factsObject

Breakes down blocked groups in blocked facts



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/facter/framework/config/fact_groups.rb', line 23

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



53
54
55
56
57
58
59
60
# File 'lib/facter/framework/config/fact_groups.rb', line 53

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



36
37
38
39
40
41
42
43
44
# File 'lib/facter/framework/config/fact_groups.rb', line 36

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}.*/ } }
  @groups.detect do |k, v|
    break k if Array(v).find { |f| fact_name.include?('.*') ? fact_name == f : fact_name =~ /^#{f}.*/ }
  end
end

#get_group_ttls(group_name) ⇒ Object

Get config ttls for a given group



47
48
49
50
51
# File 'lib/facter/framework/config/fact_groups.rb', line 47

def get_group_ttls(group_name)
  return unless (ttls = @groups_ttls.find { |g| g[group_name] })

  ttls_to_seconds(ttls[group_name])
end