Class: Benry::ActionRunner::Brownie

Inherits:
Object
  • Object
show all
Defined in:
lib/benry/actionrunner.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Brownie

Returns a new instance of Brownie.



273
274
275
# File 'lib/benry/actionrunner.rb', line 273

def initialize(config)
  @config = config
end

Instance Method Details

#populate_global_variables(global_vars) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/benry/actionrunner.rb', line 322

def populate_global_variables(global_vars)
  #; [!cr2ph] sets global variables.
  #; [!3kow3] normalizes global variable names.
  #; [!03x7t] decodes JSON string into Ruby object.
  #; [!1ol4a] print global variables if debug mode is on.
  global_vars.each do |name, str|
    var = name.gsub(/[^\w]/, '_')
    val = _decode_value(str)
    eval "$#{var} = #{val.inspect}"
    _debug_global_var(var, val) if $DEBUG_MODE
  end
  nil
end

#render_action_file_content(filename) ⇒ Object



358
359
360
361
362
363
364
365
# File 'lib/benry/actionrunner.rb', line 358

def render_action_file_content(filename)
  #; [!oc03q] returns content of action file.
  #content = DATA.read()
  content = File.read(__FILE__, encoding: 'utf-8').split(/\n__END__\n/)[-1]
  content = content.gsub('%COMMAND%', @config.app_command)
  content = content.gsub('%ACTIONFILE%', filename)
  return content
end

#search_and_load_action_file(filename, flag_search, flag_chdir, _pwd: Dir.pwd()) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/benry/actionrunner.rb', line 277

def search_and_load_action_file(filename, flag_search, flag_chdir, _pwd: Dir.pwd())
  #; [!c9e1h] if action file exists in current dir, load it regardless of options.
  #; [!m5oj7] if action file exists in parent dir, find and load it if option '-s' specified.
  if File.exist?(filename) ; dir = "."
  elsif flag_search        ; dir = _search_dir_where_file_exist(filename, _pwd)
  else                     ; dir = nil
  end
  #; [!079xs] returns nil if action file not found.
  #; [!7simq] changes current dir to where action file exists if option '-w' specified.
  #; [!dg2qv] action file can has directory path.
  if    dir == nil ; return nil
  elsif dir == "." ; fpath = filename
  elsif flag_chdir ; fpath = filename ; _chdir(dir)
  else             ; fpath = File.join(dir, filename)
  end
  #; [!d987b] loads action file if exists.
  abspath = File.absolute_path(fpath)
  require abspath
  #; [!x9xxl] returns absolute path of action file if exists.
  return abspath
end