Class: Bigrig::Container

Inherits:
BaseModel show all
Defined in:
lib/bigrig/models/container.rb

Constant Summary collapse

ARRAY_ATTRS =
:volumes_from, :links, :hosts, :volumes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*opts) ⇒ Container

Returns a new instance of Container.



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bigrig/models/container.rb', line 25

def initialize(*opts)
  super
  @env ||= {}
  @ports ||= []

  ARRAY_ATTRS.map { |a| "@#{a}" }.each do |attr|
    instance_variable_get(attr) || instance_variable_set(attr, [])
  end

  # Yes rubocop, I know this is a very stupid thing to do
  @env = Hash[*@env.map { |k, v| [k, eval("\"#{v}\"")] }.flatten] # rubocop:disable Lint/Eval
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def env
  @env
end

#hostsObject

Returns the value of attribute hosts.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def hosts
  @hosts
end

Returns the value of attribute links.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def links
  @links
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def name
  @name
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def path
  @path
end

#portsObject

Returns the value of attribute ports.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def ports
  @ports
end

#repoObject

Returns the value of attribute repo.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def repo
  @repo
end

#scanObject

Returns the value of attribute scan.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def scan
  @scan
end

#tagObject

Returns the value of attribute tag.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def tag
  @tag
end

#volumesObject

Returns the value of attribute volumes.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def volumes
  @volumes
end

#volumes_fromObject

Returns the value of attribute volumes_from.



4
5
6
# File 'lib/bigrig/models/container.rb', line 4

def volumes_from
  @volumes_from
end

Class Method Details

.from_json(name, json) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/bigrig/models/container.rb', line 8

def from_json(name, json)
  opts = [:env, :path, :ports, :tag,
          :repo, :scan].each_with_object(name: name) do |e, o|
    o[e] = json.send :[], e.to_s
  end
  ARRAY_ATTRS.each { |x| opts[x] = as_array json[x.to_s] }

  Container.new opts
end

Instance Method Details

#dependenciesObject



38
39
40
# File 'lib/bigrig/models/container.rb', line 38

def dependencies
  volumes_from + links.map { |l| l.split(':').first }
end