Class: Gat::Base
- Inherits:
-
Object
- Object
- Gat::Base
- Defined in:
- lib/gat.rb
Overview
Gat::Base Class
Gat::Base provides basic features, like logger, times, debug levels, a launcher controlled by exceptions and command line parsed Base class is, as we see, the container. It control the config and the whole process. But it is only the container, the process itlsef is runned by actions, conditions or operations.
Gat::Base include then, methods to collect config information, mess the time, launch the script, etc… features that are usually needed by almost of the scripts
Gat::Base now, delegate the execution to the Gat::Operation, but, we want that Gat::Base provides interaction framework, for example, interact with machine, creating onfly actions
Direct Known Subclasses
GatgetDarBackup, GatgetGatgetsManager, GatgetSynchronization
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#config ⇒ Object
readonly
set read only attributes.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#onfail_error ⇒ Object
Returns the value of attribute onfail_error.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#times ⇒ Object
readonly
set read && write attributes.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#execute ⇒ Object
Execute the gatget Now, this method just call the current operation and run it.
-
#get_dependence_value(dependence_type, dependence_name) ⇒ Object
Return the dependence value only arguments, folders, programs, static, variable are allowed.
- #get_dependence_variable(variable_name) ⇒ Object
-
#get_element_config(element_type, element_name) ⇒ Object
Return the config for a defined gatget element structure only arguments, folders, programs, actions, conditions, outputs element_types are allowed.
-
#get_flag(flag_name) ⇒ Object
Get flag value.
-
#initialize(options = {}, arguments = []) ⇒ Base
constructor
Initializes the Gat.Base class, reading the yaml script and any templates.
-
#set_dependence_variable(variable_name, variable_value) ⇒ Object
Set a value for a variable to be used along the script Override variable is warned at warning level.
-
#set_flag(flag_name, true_or_false) ⇒ Object
Set flag value.
Methods included from Email
#create_and_deliver_email, #new_email, #send_email
Methods included from Launcher
Methods included from Help
Methods included from Debug
#get_debug_levels, #print_debug_msg
Methods included from Checks
#check_enough_space, #check_false, #check_file_exists, #check_file_not_exists, #check_i_am_running, #check_true, #exit_if_i_am_running, #need_arguments
Constructor Details
#initialize(options = {}, arguments = []) ⇒ Base
Initializes the Gat.Base class, reading the yaml script and any templates. Gat set a lot of variable accessors
-
logger: through log method, store all the ouputs of a gatget process
-
times: stores times references
-
config: gatget config merged with option passed to the script
-
dependences: needed information through the process
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gat.rb', line 86 def initialize( = {}, arguments = []) @logger = Logger.new(self) # start gatget_logger @times = Hash.new # store time @times['init'] = Time.now @debug,arguments = debug?(arguments) # load_debug @verbose,arguments = verbose?(arguments) # load_verbose @config = set_gatget_config() # load config @arguments = arguments @logger.log("message", "gatget", "Initialize #{ self.name } < #{ self.class.superclass.name } at script #{ $0 }" ) @logger.log("message", "gatget", "Gat::Version: #{ Gat::VERSION }, http://www.gnoxys.net") # ToDO # Gat, at this time, is only a operation framework. I mean, a gatget has many operation, # like gat_password store_password || view_password. # Then, at this point of development, we care only about these operations. But, # inside gat planning, we want not only run operation but simulations or interactive # programs, that doesnt have a start.steps.end structure, like console # # @operation, is though to be remove for gat::mode at future # @operation = build_operation(arguments) # load operation @variables = { } # variables are empty at start @flags = { } # flags are empty at start end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
61 62 63 |
# File 'lib/gat.rb', line 61 def arguments @arguments end |
#config ⇒ Object (readonly)
set read only attributes
60 61 62 |
# File 'lib/gat.rb', line 60 def config @config end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
63 64 65 |
# File 'lib/gat.rb', line 63 def debug @debug end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
73 74 75 |
# File 'lib/gat.rb', line 73 def flags @flags end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
71 72 73 |
# File 'lib/gat.rb', line 71 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
65 66 67 |
# File 'lib/gat.rb', line 65 def name @name end |
#onfail_error ⇒ Object
Returns the value of attribute onfail_error.
75 76 77 |
# File 'lib/gat.rb', line 75 def onfail_error @onfail_error end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
62 63 64 |
# File 'lib/gat.rb', line 62 def operation @operation end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
66 67 68 |
# File 'lib/gat.rb', line 66 def path @path end |
#times ⇒ Object (readonly)
set read && write attributes
70 71 72 |
# File 'lib/gat.rb', line 70 def times @times end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
72 73 74 |
# File 'lib/gat.rb', line 72 def variables @variables end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
64 65 66 |
# File 'lib/gat.rb', line 64 def verbose @verbose end |
Instance Method Details
#execute ⇒ Object
Execute the gatget Now, this method just call the current operation and run it. As interactive mode, and after set dependences, execute method will run also @operations or another interactive process
200 201 202 203 204 205 206 |
# File 'lib/gat.rb', line 200 def execute if self.operation self.operation.execute else raise GatgetConfigException("Operation is undefined!", "gatget_execute") end end |
#get_dependence_value(dependence_type, dependence_name) ⇒ Object
Return the dependence value only arguments, folders, programs, static, variable are allowed
raise GatgetConfigException if none found
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/gat.rb', line 142 def get_dependence_value(dependence_type, dependence_name) unless ['arguments', 'folders', 'programs', 'static', 'variable', 'flags', 'action_output'].include?(dependence_type) raise GatgetConfigException.new("undefined gat dependence type #{ dependence_type }", "get_dependence_value") end case dependence_type when 'static' ret = self.config['static'][dependence_name] when 'variable' ret = self.variables[dependence_name] when 'folders' dependence_folders = self.operation.send(dependence_type).select { |dependence| dependence_name[/^#{ dependence.name }/]} if dependence_folders.any? ret = dependence_folders.first.value(dependence_name) else ret = nil end when 'action_output' ret = self.operation.get_action(dependence_name).output else values = self.operation.send(dependence_type) if values.any? ret = values.select { |dependence| dependence_name == dependence.name }.first.value else raise GatgetConfigException.new("Empty dependence '#{dependence_type}', for operation '#{self.operation.name}'", "get_dependence_value") end end end |
#get_dependence_variable(variable_name) ⇒ Object
134 135 136 |
# File 'lib/gat.rb', line 134 def get_dependence_variable( variable_name ) get_dependence_value('variable', variable_name) end |
#get_element_config(element_type, element_name) ⇒ Object
Return the config for a defined gatget element structure only arguments, folders, programs, actions, conditions, outputs element_types are allowed
raise GatgetConfigException if none found
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gat.rb', line 122 def get_element_config(element_type, element_name) unless ['arguments', 'folders', 'programs', 'actions', 'conditions', 'parameters'].include?(element_type) raise GatgetConfigException.new("undefined gat element type #{ element_type } in YML structure", "get_element_config") end @config[element_type] || raise(GatgetConfigException.new("'#{ element_type.capitalize }' section not defined in YML structure", "get_element_config")) @config[element_type][element_name] || raise(GatgetConfigException.new("'#{ element_type.capitalize }/#{ element_name }' element not found in YML structure", "get_element_config")) end |
#get_flag(flag_name) ⇒ Object
Get flag value
188 189 190 191 192 193 194 195 |
# File 'lib/gat.rb', line 188 def get_flag(flag_name) ret = self.flags[flag_name] if ret == nil self.operation.gatget.logger.log("warning", "get_flag", "Undefined flag #{flag_name}") ret = false end ret end |
#set_dependence_variable(variable_name, variable_value) ⇒ Object
Set a value for a variable to be used along the script Override variable is warned at warning level
174 175 176 177 178 179 180 |
# File 'lib/gat.rb', line 174 def set_dependence_variable(variable_name, variable_value) if self.variables[variable_name] @logger.log("warning", "dependence", "#{ self.class } rewrite variable #{ variable_name } at #{ Time.now }") end self.variables[variable_name] = variable_value end |
#set_flag(flag_name, true_or_false) ⇒ Object
Set flag value
183 184 185 |
# File 'lib/gat.rb', line 183 def set_flag(flag_name, true_or_false) self.flags[flag_name] = true_or_false end |