Class: Envirobly::Configs

Inherits:
Object show all
Defined in:
lib/envirobly/configs.rb

Constant Summary collapse

DIR =
".envirobly"
ENV =
"env"
BASE =
"deploy.yml"
OVERRIDES_PATTERN =
/deploy\.([a-z0-9\-_]+)\.yml/i
DEFAULTS_DIR =
File.join DIR, "defaults"
DEFAULT_ACCOUNT_PATH =
File.join(DEFAULTS_DIR, "account.yml")
DEFAULT_PROJECT_PATH =
File.join(DEFAULTS_DIR, "project.yml")

Instance Method Summary collapse

Constructor Details

#initialize(dir = DIR) ⇒ Configs

Returns a new instance of Configs.



12
13
14
# File 'lib/envirobly/configs.rb', line 12

def initialize(dir = DIR)
  @dir = Pathname.new dir
end

Instance Method Details

#default_account_idObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/envirobly/configs.rb', line 34

def 
  if File.exist?(DEFAULT_ACCOUNT_PATH)
    content = YAML.safe_load_file(DEFAULT_ACCOUNT_PATH)
    if content["url"] =~ /accounts\/(\d+)/
      return $1.to_i
    end
  end

  nil
end

#default_project_idObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/envirobly/configs.rb', line 23

def default_project_id
  if File.exist?(DEFAULT_PROJECT_PATH)
    content = YAML.safe_load_file(DEFAULT_PROJECT_PATH)
    if content["url"] =~ /projects\/(\d+)/
      return $1.to_i
    end
  end

  nil
end

#save_default_account(url) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/envirobly/configs.rb', line 45

def (url)
  return if File.exist?(DEFAULT_ACCOUNT_PATH)

  FileUtils.mkdir_p(DEFAULTS_DIR)
  content = YAML.dump({ "url" => url })
  File.write(DEFAULT_ACCOUNT_PATH, content)
end

#save_default_project(url) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/envirobly/configs.rb', line 53

def save_default_project(url)
  return if File.exist?(DEFAULT_PROJECT_PATH)

  FileUtils.mkdir_p(DEFAULTS_DIR)
  content = YAML.dump({ "url" => url })
  File.write(DEFAULT_PROJECT_PATH, content)
end

#to_paramsObject



16
17
18
19
20
21
# File 'lib/envirobly/configs.rb', line 16

def to_params
  {
    configs:,
    env_vars:
  }
end