class Dockit::Env
This class encapsulates the environment used in the Dockit
cli. The class has three main attributes:
- root
-
The (cached) root of the project.
- modules
-
The “modules”, a map of
Dockit.rb
files by directory name - services
-
The “services”, a map of
Dockit.yaml
files, by directory name
Constants
- BASENAME
Attributes
modules[R]
services[R]
Public Class Methods
new(depth: 2, debug: false)
click to toggle source
Initialize services and modules in the project.
- depth [Integer]
-
How deep to recurse looking for modules/services
- debug [Boolean]
-
Log
docker-api
calls.
# File lib/dockit.rb, line 69 def initialize(depth: 2, debug: false) @root = nil @modules = find_subcommands(depth) @services = find_services(depth) Docker.logger = Dockit::Log.new if debug end
Public Instance Methods
root()
click to toggle source
The (cached) root of the project
- Returns [String]
-
The absolute path of the project root.
# File lib/dockit.rb, line 80 def root return @root if @root @root = dir = Dir.pwd begin dir = File.dirname(dir) return @root = dir if File.exist?(File.join(dir, "#{BASENAME}.rb")) end while dir != '/' @root end
Private Instance Methods
find_relative(depth, ext)
click to toggle source
# File lib/dockit.rb, line 100 def find_relative(depth, ext) result = {} (0..depth).each do |i| pat = File.join(root, ['*'] * i, "#{BASENAME}.#{ext}") Pathname.glob(pat).inject(result) do |memo, path| name = path.dirname.relative_path_from(Pathname.new(root)).to_s name = 'all' if name == '.' memo[name] = path.to_s memo end end result end
find_services(depth)
click to toggle source
# File lib/dockit.rb, line 92 def find_services(depth) find_relative(depth, 'yaml') end
find_subcommands(depth)
click to toggle source
# File lib/dockit.rb, line 96 def find_subcommands(depth) find_relative(depth, 'rb') end