File: docker_base.rb

package info (click to toggle)
ruby-serverspec 2.42.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 980 kB
  • sloc: ruby: 4,835; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 560 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'multi_json'

module Serverspec::Type
  class DockerBase < Base
    def exist?
      get_inspection.success?
    end

    def [](key)
      value = inspection
      key.split('.').each do |k|
        is_index = k.start_with?('[') && k.end_with?(']')
        value = value[is_index ? k[1..-2].to_i : k]
      end
      value
    end

    def inspection
      @inspection ||= ::MultiJson.load(get_inspection.stdout)[0]
    end

    private
    def get_inspection
      @get_inspection ||= @runner.run_command("docker inspect #{@name}")
    end
  end
end