Class: Jira::Auto::Tool::EnvironmentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/jira/auto/tool/environment_loader.rb,
lib/jira/auto/tool/environment_loader/options.rb

Defined Under Namespace

Modules: Options

Constant Summary collapse

CURRENT_DIR =
"."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool, auto_setup: true) ⇒ EnvironmentLoader

Returns a new instance of EnvironmentLoader.



9
10
11
12
13
# File 'lib/jira/auto/tool/environment_loader.rb', line 9

def initialize(tool, auto_setup: true)
  @tool = tool

  setup if auto_setup
end

Instance Attribute Details

#toolObject (readonly)

Returns the value of attribute tool.



7
8
9
# File 'lib/jira/auto/tool/environment_loader.rb', line 7

def tool
  @tool
end

Instance Method Details

#create_fileObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/jira/auto/tool/environment_loader.rb', line 15

def create_file
  if File.exist?(file_path)
    log.error do
      <<~EOERRORMESSAGE
        Not overriding existing #{file_path}
        ______________________________________________
        Please remove first before running this again!
      EOERRORMESSAGE
    end

    Kernel.exit 1
  else
    FileUtils.cp(example_file_path, file_path)

    log.info do
      <<~EOMESSAGE
        Created file #{file_path}
        _______________________________________________
        TODO: Adjust the configuration to your context!
      EOMESSAGE
    end
  end
end

#environment_variable_holds_a_secret?(env_var_name) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/jira/auto/tool/environment_loader.rb', line 56

def environment_variable_holds_a_secret?(env_var_name)
  method_name = env_var_name.to_s.downcase
  tool.send("#{method_name}_holds_a_secret?")
end

#example_file_pathObject



65
66
67
# File 'lib/jira/auto/tool/environment_loader.rb', line 65

def example_file_path
  File.join(tool.home_dir, "config/examples", file_basename)
end

#file_pathObject



61
62
63
# File 'lib/jira/auto/tool/environment_loader.rb', line 61

def file_path
  File.exist?(current_dir_file_path) ? current_dir_file_path : config_dir_file_path
end

#listObject



39
40
41
42
43
44
# File 'lib/jira/auto/tool/environment_loader.rb', line 39

def list
  $stdout.puts <<~EOLIST
    #{configuration_source_string}
    #{table}
  EOLIST
end

#tool_environmentObject



46
47
48
49
50
51
52
53
54
# File 'lib/jira/auto/tool/environment_loader.rb', line 46

def tool_environment
  Environment.constants.sort.to_h do |constant|
    constant_as_string = constant.to_s
    actual_value = ENV.fetch(constant_as_string, nil)
    value_to_display = environment_variable_holds_a_secret?(constant_as_string) ? "****" : actual_value

    [constant_as_string, value_to_display]
  end
end