Class: Tomo::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/configuration.rb,
lib/tomo/configuration/dsl.rb,
lib/tomo/configuration/glob.rb,
lib/tomo/configuration/environment.rb,
lib/tomo/configuration/dsl/batch_block.rb,
lib/tomo/configuration/dsl/config_file.rb,
lib/tomo/configuration/dsl/tasks_block.rb,
lib/tomo/configuration/plugins_registry.rb,
lib/tomo/configuration/dsl/error_formatter.rb,
lib/tomo/configuration/unknown_plugin_error.rb,
lib/tomo/configuration/dsl/environment_block.rb,
lib/tomo/configuration/dsl/hosts_and_settings.rb,
lib/tomo/configuration/role_based_task_filter.rb,
lib/tomo/configuration/project_not_found_error.rb,
lib/tomo/configuration/unknown_environment_error.rb,
lib/tomo/configuration/plugin_file_not_found_error.rb,
lib/tomo/configuration/plugins_registry/gem_resolver.rb,
lib/tomo/configuration/unspecified_environment_error.rb,
lib/tomo/configuration/plugins_registry/file_resolver.rb

Defined Under Namespace

Modules: DSL Classes: Environment, Glob, PluginFileNotFoundError, PluginsRegistry, ProjectNotFoundError, RoleBasedTaskFilter, UnknownEnvironmentError, UnknownPluginError, UnspecifiedEnvironmentError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



31
32
33
34
35
36
37
38
39
# File 'lib/tomo/configuration.rb', line 31

def initialize
  @environments = {}
  @hosts = []
  @plugins = []
  @settings = {}
  @deploy_tasks = []
  @setup_tasks = []
  @task_filter = RoleBasedTaskFilter.new
end

Instance Attribute Details

#deploy_tasksObject

Returns the value of attribute deploy_tasks.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def deploy_tasks
  @deploy_tasks
end

#environmentsObject

Returns the value of attribute environments.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def environments
  @environments
end

#hostsObject

Returns the value of attribute hosts.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def hosts
  @hosts
end

#pathObject

Returns the value of attribute path.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def path
  @path
end

#pluginsObject

Returns the value of attribute plugins.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def plugins
  @plugins
end

#settingsObject

Returns the value of attribute settings.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def settings
  @settings
end

#setup_tasksObject

Returns the value of attribute setup_tasks.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def setup_tasks
  @setup_tasks
end

#task_filterObject

Returns the value of attribute task_filter.



29
30
31
# File 'lib/tomo/configuration.rb', line 29

def task_filter
  @task_filter
end

Class Method Details

.from_config_rb(path = DEFAULT_CONFIG_PATH) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/tomo/configuration.rb', line 16

def self.from_config_rb(path=DEFAULT_CONFIG_PATH)
  ProjectNotFoundError.raise_with(path:) unless File.file?(path)
  Tomo.logger.debug("Loading configuration from #{path.inspect}")
  config_rb = File.read(path)

  new.tap do |config|
    config.path = File.expand_path(path)
    DSL::ConfigFile.new(config).instance_eval(config_rb, path.to_s, 1)
  end
rescue StandardError, SyntaxError => e
  raise DSL::ErrorFormatter.decorate(e, path, config_rb&.lines)
end

Instance Method Details

#build_runtimeObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tomo/configuration.rb', line 51

def build_runtime
  validate_environment!(nil)
  plugins_registry = register_plugins

  Runtime.new(
    deploy_tasks:,
    setup_tasks:,
    plugins_registry:,
    hosts: add_log_prefixes(hosts),
    settings: { tomo_config_file_path: path }.merge(settings),
    task_filter:
  )
end

#for_environment(environment) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tomo/configuration.rb', line 41

def for_environment(environment)
  validate_environment!(environment)

  dup.tap do |copy|
    copy.environments = {}
    copy.hosts = hosts_for(environment)
    copy.settings = settings_with_env_overrides(environment)
  end
end