class DockerSync::ProjectConfig
Constants
- ERROR_MISMATCH_CONFIG_VERSION
- ERROR_MISSING_CONFIG_VERSION
- ERROR_MISSING_SYNCS
- REQUIRED_CONFIG_VERSION
Attributes
config[R]
config_path[R]
Public Class Methods
new(config_path: nil, config_string: nil)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 28 def initialize(config_path: nil, config_string: nil) if config_string.nil? if config_path.nil? || config_path.empty? config_path = DockerSync::ConfigLocator.lookup_project_config_path end load_project_config(config_path) else @config = DockerSync::ConfigSerializer.default_deserializer_string(config_string) @config_path = nil end validate_config! normalize_config! end
Public Instance Methods
fswatch_required?()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 64 def fswatch_required? # noinspection RubyUnusedLocalVariable config['syncs'].any? { |name, sync_config| sync_config['watch_strategy'] == 'fswatch' } end
load_project_config(config_path = nil)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 44 def load_project_config(config_path = nil) @config_path = config_path return unless File.exist?(@config_path) @config = DockerSync::ConfigSerializer.default_deserializer_file(@config_path) end
rsync_required?()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 57 def rsync_required? # noinspection RubyUnusedLocalVariable config['syncs'].any? { |name, sync_config| sync_config['sync_strategy'] == 'rsync' } end
unison_required?()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 50 def unison_required? # noinspection RubyUnusedLocalVariable config['syncs'].any? { |name, sync_config| sync_config['sync_strategy'] == 'unison' || sync_config['watch_strategy'] == 'unison' } end
Private Instance Methods
default_sync_strategy()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 145 def default_sync_strategy return 'native' if Environment.linux? return 'native_osx' if Environment.mac? && Dependencies::Docker::Driver.docker_for_mac? return 'unison' if Environment.mac? end
default_watch_strategy(sync_config)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 151 def default_watch_strategy(sync_config) case sync_strategy_for(sync_config) when 'rsync' then 'fswatch' when 'unison' then 'unison' when 'native' then 'dummy' when 'native_osx' then 'remotelogs' else raise "you shouldn't be here" end end
error_missing_given_config()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 97 def error_missing_given_config "Config could not be loaded from #{config_path} - it does not exist" end
expand_path(path)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 161 def expand_path(path) Dir.chdir(project_root) { # [nbr] convert the sync src from relative to absolute path # preserve '/' as it may be significant to the sync cmd absolute_path = File.expand_path(path) absolute_path << '/' if path.end_with?('/') absolute_path } end
normalize_config!()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 101 def normalize_config! normalize_options_config! config['syncs'].each do |name, sync_config| config['syncs'][name] = normalize_sync_config(sync_config) end end
normalize_options_config!()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 109 def normalize_options_config! config['options'] = { 'project_root' => 'pwd', }.merge(config['options'] || {}) end
normalize_sync_config(sync_config)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 115 def normalize_sync_config(sync_config) { 'sync_strategy' => sync_strategy_for(sync_config), 'watch_strategy' => watch_strategy_for(sync_config) }.merge(sync_config).merge( 'src' => expand_path(sync_config['src']), ) end
project_root()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 171 def project_root if use_config_path_for_project_root? File.dirname(@config_path) else Dir.pwd end end
sync_strategy_for(sync_config)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 124 def sync_strategy_for(sync_config) sync_strategy = sync_config['sync_strategy'] if %w(rsync unison native native_osx).include?(sync_strategy) sync_strategy else default_sync_strategy end end
use_config_path_for_project_root?()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 179 def use_config_path_for_project_root? config['options']['project_root'] == 'config_path' && !(@config_path.nil? || @config_path.empty?) end
validate_config!()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 73 def validate_config! raise error_missing_given_config if config.nil? raise ERROR_MISSING_CONFIG_VERSION unless config.key?('version') raise ERROR_MISMATCH_CONFIG_VERSION unless config['version'].to_s == REQUIRED_CONFIG_VERSION raise ERROR_MISSING_SYNCS unless config.key?('syncs') validate_syncs_config! end
validate_sync_config(name, sync_config)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 88 def validate_sync_config(name, sync_config) config_mandatory = %w[src] #TODO: Implement autodisovery for other strategies config_mandatory.push('sync_host_port') if sync_config['sync_strategy'] == 'rsync' config_mandatory.each do |key| raise ("#{name} does not have #{key} configuration value set - this is mandatory") unless sync_config.key?(key) end end
validate_syncs_config!()
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 82 def validate_syncs_config! config['syncs'].each do |name, sync_config| validate_sync_config(name, sync_config) end end
watch_strategy_for(sync_config)
click to toggle source
# File lib/docker-sync/config/project_config.rb, line 134 def watch_strategy_for(sync_config) watch_strategy = sync_config['watch_strategy'] watch_strategy = 'dummy' if watch_strategy == 'disable' if %w(fswatch unison dummy).include?(watch_strategy) watch_strategy else default_watch_strategy(sync_config) end end