Class: Facter::FactGroups

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/framework/config/fact_groups.rb

Constant Summary collapse

STRING_TO_SECONDS =
{ 'ns' => 1.fdiv(1_000_000_000), 'nanos' => 1.fdiv(1_000_000_000),
'nanoseconds' => 1.fdiv(1_000_000_000),
'us' => 1.fdiv(1_000_000), 'micros' => 1.fdiv(1_000_000), 'microseconds' => 1.fdiv(1_000_000),
'' => 1.fdiv(1000), 'ms' => 1.fdiv(1000), 'milis' => 1.fdiv(1000),
'milliseconds' => 1.fdiv(1000),
's' => 1, 'seconds' => 1,
'm' => 60, 'minutes' => 60,
'h' => 3600, 'hours' => 3600,
'd' => 3600 * 24, 'days' => 3600 * 24 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFactGroups

Returns a new instance of FactGroups.



20
21
22
23
24
25
26
27
28
# File 'lib/facter/framework/config/fact_groups.rb', line 20

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



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

def blocked_facts
  fact_list = []

  @block_list.each do |group_name|
    # legacy is a special group and does not need to be broken into facts
    next if group_name == 'legacy'

    facts_for_block = @groups[group_name]

    fact_list += facts_for_block || [group_name]
  end

  fact_list
end

#get_fact(fact_name) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/facter/framework/config/fact_groups.rb', line 64

def get_fact(fact_name)
  return @facts_ttls[fact_name] if @facts_ttls[fact_name]

  result = @facts_ttls.select { |name, fact| break fact if /^#{name}\..*/.match?(fact_name) }
  return nil if result == {}

  result
end

#get_fact_group(fact_name) ⇒ Object

Get the group name a fact is part of



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

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



58
59
60
61
62
# File 'lib/facter/framework/config/fact_groups.rb', line 58

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

  ttls_to_seconds(ttls[group_name])
end