Module: Conductor::Env

Defined in:
lib/conductor/env.rb

Overview

Environment variables

Class Method Summary collapse

Class Method Details

.envObject

Define @env using Marked environment variables



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/conductor/env.rb', line 9

def self.env
  if ENV["CONDUCTOR_TEST"]&.to_bool
    load_test_env
  else
    @env ||= {
      home: ENV["HOME"],
      css_path: ENV["MARKED_CSS_PATH"],
      ext: ENV["MARKED_EXT"],
      includes: ENV["MARKED_INCLUDES"].split_list,
      origin: ENV["MARKED_ORIGIN"],
      filepath: ENV["MARKED_PATH"],
      filename: File.basename(ENV["MARKED_PATH"]),
      phase: ENV["MARKED_PHASE"],
      outline: ENV["OUTLINE"],
      path: ENV["PATH"]
    }
  end

  @env
end

.load_test_envObject

Loads a test environment.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/conductor/env.rb', line 33

def self.load_test_env
  @env = {
    home: "/Users/ttscoff",
    css_path: "/Applications/Marked 2.app/Contents/Resources/swiss.css",
    ext: "md",
    includes: "".split_list,
    origin: "/Users/ttscoff/Sites/dev/bt/source/_posts/",
    filepath: "/Users/ttscoff/Sites/dev/bt/source/_posts/2024-04-01-automating-the-dimspirations-workflow.md",
    filename: "advanced-features.md",
    phase: "PROCESS",
    outline: "NONE",
    path: "/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/ttscoff/Sites/dev/bt/source/_posts"
  }
end

.to_sString

env to shell-compatible string

Returns:

  • (String)

    shell-compatible string representation of @env



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/conductor/env.rb', line 53

def self.to_s
  {
    "HOME" => @env[:home],
    "MARKED_CSS_PATH" => @env[:css_path],
    "MARKED_EXT" => @env[:ext],
    "MARKED_ORIGIN" => @env[:origin],
    "MARKED_INCLUDES" => @env[:includes].shell_join.join(","),
    "MARKED_PATH" => @env[:filepath],
    "MARKED_PHASE" => @env[:phase],
    "OUTLINE" => @env[:outline],
    "PATH" => @env[:path]
  }.map { |k, v| %(#{k}="#{v}") }.join(" ").force_encoding("utf-8")
end