Class: Envirobly::Config

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

Constant Summary collapse

DIR =
".envirobly"
PATH =
"#{DIR}/project.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commit) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
18
# File 'lib/envirobly/config.rb', line 11

def initialize(commit)
  @commit = commit
  @errors = []
  @result = {}
  @project_url = nil
  @raw = @commit.file_content PATH
  @project = parse
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/envirobly/config.rb', line 9

def errors
  @errors
end

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/envirobly/config.rb', line 9

def raw
  @raw
end

#resultObject (readonly)

Returns the value of attribute result.



9
10
11
# File 'lib/envirobly/config.rb', line 9

def result
  @result
end

Instance Method Details

#compile(environment = nil) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/envirobly/config.rb', line 33

def compile(environment = nil)
  return unless @project
  @environment = environment
  @result = @project.slice(:services)
  set_project_url
  merge_environment_overrides! unless @environment.nil?
  append_image_tags!
end

#dig(*args) ⇒ Object



20
21
22
23
24
# File 'lib/envirobly/config.rb', line 20

def dig(*args)
  @project.dig(*args)
rescue NoMethodError
  nil
end

#to_deployment_paramsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/envirobly/config.rb', line 42

def to_deployment_params
  {
    environ: {
      name: @environment,
      project_url: @project_url
    },
    commit: {
      ref: @commit.ref,
      time: @commit.time,
      message: @commit.message
    },
    config: @result,
    raw_config: @raw
  }
end

#validateObject



26
27
28
29
30
31
# File 'lib/envirobly/config.rb', line 26

def validate
  return unless @project
  validate_top_level_keys
  validate_services @project.fetch(:services)
  validate_environments
end