Class: SafeDb::FactFind
- Inherits:
-
Object
- Object
- SafeDb::FactFind
- Defined in:
- lib/utils/facts/fact.rb
Overview
– – —————– – Fact Production – —————– – – The fact tree is tasked with fact production – (population). Fact production is done by [consuming] – – [1] - simple string, number of boolean facts – [2] - facts already produced – [3] - identity facts from command line and environment – [4] - software (behaviour) that derives facts – [5] - inherited (extended) facts from (OO) parents – – – – —————————————– – The 4 Universal (DevOps) Creation Facts – —————————————– – – No matter the (DevOps) eco-system being fabricated, these four – facts prevail and stand out. – – Every time a DevOps [eco-system] is created, cloned, or recovered, – a small cluster of core facts endure to define the instance and act – as the identification basis of all new eco-system resources. – – The 4 facts underpinning eco-system creation are – – [1] - [what] is being built – [2] - [when] did the building begin – [3] - [who] instigated it (and from) – [4] - [which] workstation. – – ————————————— – DevOps 4 Creational [Instance] Facts – ————————————— – – The core instance identities used and reused time and again relate to – – [1] - plugin (eg) wordpress.hub or jenkins.hub – [2] - time (eg) 18036.0952.065 – [3] - user (eg) peterpan – [4] - workstation (eg) laptop_susie or hp_desktop – –
Constant Summary collapse
- @@eval_prefix =
"rb>>"
Instance Attribute Summary collapse
-
#f ⇒ Object
readonly
The fact tree values can be referenced using the @f specifier with a 2 dimensional key.
Instance Method Summary collapse
-
#assimilate(factfile_name) ⇒ Object
Assimilate the gem’s main factbase fact file into the structure that is exposed to outside classes as the instance variable @f (a 2D array type).
-
#assimilate_fact(fact_group_str, fact_key_str, fact_value_str) ⇒ Object
This method assimilates a two-dimensional fact bringing it into the fact tree fold.
-
#assimilate_ini_file(ini_filepath) ⇒ Object
– ——————————————- – # – – # – Template – # – – # – The longest river in africa is without – # – doubt the @[africa|longest.river].
-
#initialize ⇒ FactFind
constructor
This method constructs the FactFind object and tree database and initializers the root fact container structures.
-
#to_symbol(from_string) ⇒ Object
This static method converts from string to symbol.
Constructor Details
#initialize ⇒ FactFind
This method constructs the FactFind object and tree database and initializers the root fact container structures.
62 63 64 65 66 67 68 69 70 |
# File 'lib/utils/facts/fact.rb', line 62 def initialize @f = {} @s = {} # ---> @f.store symbol(plugin_id), {} # ---> @p = @f[symbol(plugin_id)] end |
Instance Attribute Details
#f ⇒ Object (readonly)
The fact tree values can be referenced using the @f specifier with a 2 dimensional key.
57 58 59 |
# File 'lib/utils/facts/fact.rb', line 57 def f @f end |
Instance Method Details
#assimilate(factfile_name) ⇒ Object
Assimilate the gem’s main factbase fact file into the structure that is exposed to outside classes as the instance variable @f (a 2D array type).
The factfile to assimilate is always expected to exist in folder [ ../factbase ]
The factfile name within the above folder is expected to be presented in the parameter.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/utils/facts/fact.rb', line 84 def assimilate factfile_name factfile_dir = File.join(File.dirname(File.(__FILE__)), "../factbase") factfile_path = File.join factfile_dir, factfile_name log.info(x) { "Assimilating factfile in folder => #{factfile_dir}" } log.info(x) { "Assimilating factfile with name => #{factfile_name}" } assimilate_ini_file factfile_path end |
#assimilate_fact(fact_group_str, fact_key_str, fact_value_str) ⇒ Object
This method assimilates a two-dimensional fact bringing it into the fact tree fold.
Once assimilated, this fact with a 2D index can be reused
-
for future fact resolution
-
by classes with access to the fact tree
-
for dynamic template resolution
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/utils/facts/fact.rb', line 201 def assimilate_fact fact_group_str, fact_key_str, fact_value_str grp_symbol = fact_group_str.gsub(".", "_").to_sym key_symbol = fact_key_str.gsub(".", "_").to_sym raise ArgumentError, "Assimilating Fact [ #{fact_group_str} ][ #{fact_key_str} ] => Value is NIL" if fact_value_str.nil? fact_string = fact_value_str.strip begin raise ArgumentError, "Fact object in section #{fact_group_str} with key #{fact_key_str} is nil." if fact_string.nil? eval_value = evaluate( fact_string ) add_fact grp_symbol, to_symbol(fact_key_str), eval_value rescue Exception => e log.fatal(x) { "## ##################### #################################" } log.fatal(x) { "## Fact Evaluation Error ---------------------------------" } log.fatal(x) { "## ##################### #################################" } log.fatal(x) { "## Fact Family => #{fact_group_str}" } log.fatal(x) { "## Fact Key => #{fact_key_str}" } log.fatal(x) { "## Fact Stmt => #{fact_string}" } log.fatal(x) { "## Fact Error => #{e.}" } log.fatal(x) { "## ##################### #################################" } e.backtrace.log_lines raise e end unless @f.has_key? grp_symbol then log.debug(x){ "# @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #" } log.debug(x){ "# @@ the [#{fact_group_str}] silo facts." } log.debug(x){ "# @@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #" } end id_keystring = "#{grp_symbol}#{key_symbol}".downcase sensitive = id_keystring.includes_any? [ "secret", "password", "credential", "creds" ] print_value = "****************" print_value = eval_value unless sensitive fw_key = sprintf '%-33s', "@f[:#{grp_symbol}][:#{key_symbol}]" log.debug(x){ "#{fw_key} => #{print_value}" } end |
#assimilate_ini_file(ini_filepath) ⇒ Object
– ——————————————- – # – – # – Template – # – – # – The longest river in africa is without – # – doubt the @[africa|longest.river]. Now – # – @[south.america|most.spoken] is the – # – most common language in south america. – # – – # – The population of the americas – # – is @[americas|population] according to – the Harvard 2015 census. – – # – ——————————————- – # – – # – Ruby Code – # – – # – double_north_america_pop = @f[:population] * 2 – – # – ——————————————- – # – Parameters – # – factory_facts : instantiated 2D hash – # – ini_filepath : path to factfile to read – # – – # – Dependencies and Assumptions – # – the [inifile] gem is installed – # – file exists at the ini_filepath – # – factory_facts are instantiated – # – identity facts like @i exist – # – ——————————————- – #
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/utils/facts/fact.rb', line 150 def assimilate_ini_file ini_filepath fact_filename = File.basename ini_filepath log_begin fact_filename no_file = "No (ini) factfile found here => #{ini_filepath}" raise ArgumentError.new no_file unless File.exists? ini_filepath # -- # -- Use the inifile gem to parse and read the fact # -- file contents into Ruby's map structures. # -- begin map_facts = IniFile.load ini_filepath map_facts.each do | group_str, key_str, input_value | assimilate_fact group_str, key_str, input_value end rescue Exception => e log.fatal(x) { "## ############################ #################################" } log.fatal(x) { "## Fact File Assimilation Error ---------------------------------" } log.fatal(x) { "## ############################ #################################" } log.fatal(x) { "## File => #{ini_filepath}" } log.fatal(x) { "## Error => #{e.}" } log.fatal(x) { "## ############################ #################################" } e.backtrace.log_lines log.fatal(x) { "## ############################ #################################" } raise e end log_end fact_filename end |
#to_symbol(from_string) ⇒ Object
This static method converts from string to symbol.
254 255 256 |
# File 'lib/utils/facts/fact.rb', line 254 def to_symbol from_string return from_string.strip.gsub(".", "_").to_sym end |