Class: FactLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/opensecret/plugins.io/facts/fact.locator.rb

Overview

– – Locate fact files using the stated convention when – given the name and path of a module. –

Constant Summary collapse

@@eco_factdir =
"eco.system.facts"
@@fact_endtag =
"factbase.ini"

Class Method Summary collapse

Class Method Details

.block_factdb_path(module_path, method_symbol) ⇒ Object

– – ————– – Use Case – ————– – Find path to method block scoped fact file by convention. – – ————– – Example – ————– – module_path => /home/dir/prj/street/my_flat.rb – module_dir => /home/dir/prj/street – module_name => my_flat – method_name => to_rooms – fact_folder = module_dir / eco.system.facts – – factdb_path => /home/dir/prj/eco.system.facts/my_flat.to.rooms.ini –



95
96
97
98
99
100
101
102
# File 'lib/opensecret/plugins.io/facts/fact.locator.rb', line 95

def self.block_factdb_path module_path, method_symbol

  module_name = File.basename module_path, File.extname(module_path)
  method_name = method_symbol.to_s.gsub("_", ".")
  factdb_name = module_name + "." + method_name + ".ini"
  return File.join fact_base_dir(module_path), factdb_name

end

.fact_base_dir(module_path) ⇒ Object

– – Get the [fact databases] base directory given – the full path to the requesting module. – – ———————- – Acquire Base Dir Logic – ———————- – – To acquire the base directory given the full – path to the requesting module we – – 1 => go down 2 directories (parent of parent) – 2 => go into folder eco.system.facts –



73
74
75
76
# File 'lib/opensecret/plugins.io/facts/fact.locator.rb', line 73

def self.fact_base_dir module_path
  fact_basedir = File.dirname( File.dirname( module_path ) )
  return File.join fact_basedir, @@eco_factdir
end

.hierarchy_factdb_path(module_path) ⇒ Object

– – Find path to class hierarchy fact file by convention. – – ———– – Convention – ———– – – Logic => read the module full file path – => go down 2 directories (parent of parent) – => go into folder eco.system.facts – => add database.ini to extensionless module name – – ———– – Example – ———– – – module_path => /home/dir/prj/street/my_house.rb – module_dir => /home/dir/prj – fact folder => /home/dir/prj/eco.system.facts – fact [file] => /home/dir/prj/eco.system.facts/my_house.factbase.ini – – factdb_path => /home/dir/prj/street/eco.system.facts/my_house.factbase.ini –



35
36
37
38
39
40
# File 'lib/opensecret/plugins.io/facts/fact.locator.rb', line 35

def self.hierarchy_factdb_path module_path

  module_name = File.basename module_path, File.extname(module_path)
  factdb_name = "#{module_name}.#{@@fact_endtag}"
  return File.join fact_base_dir(module_path), factdb_name
end

.keyfacts_factdb_path(module_path) ⇒ Object



43
44
45
46
47
48
# File 'lib/opensecret/plugins.io/facts/fact.locator.rb', line 43

def self.keyfacts_factdb_path module_path

  factdb_name = "facts.eco-instance.ini"
  return File.join fact_base_dir(module_path), factdb_name

end

.workstation_factdb_path(module_path) ⇒ Object



51
52
53
54
55
56
# File 'lib/opensecret/plugins.io/facts/fact.locator.rb', line 51

def self.workstation_factdb_path module_path

  factdb_name = "facts.workstation.#{NetDns.instance.host_name}.ini"
  return File.join fact_base_dir(module_path), factdb_name

end