Class: Dotsync::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/dotsync/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil, config_path: nil) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
9
# File 'lib/dotsync/runner.rb', line 5

def initialize(logger: nil, config_path: nil)
  @logger = logger || Dotsync::Logger.new
  @config_path = config_path
  Dotsync.config_path = config_path if config_path
end

Instance Method Details

#run(action_name, options = {}) ⇒ Object

action_name should be a symbol, e.g., :pull, :watch, :sync



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dotsync/runner.rb', line 12

def run(action_name, options = {})
  case action_name
  when :setup
    setup_config
  else
    begin
      action_class = Dotsync.const_get("#{camelize(action_name.to_s)}Action")
      config_class = Dotsync.const_get("#{camelize(action_name.to_s)}ActionConfig")

      config = config_class.new(Dotsync.config_path)
      Dotsync::Icons.load_custom_icons(config.to_h)
      Dotsync::Colors.load_custom_colors(config.to_h)

      action = action_class.new(config, @logger)

      action.execute(options)
    rescue ConfigError => e
      @logger.error("[#{action_name}] config error:")
      @logger.info(e.message)
    rescue NameError => e
      @logger.error("Unknown action '#{action_name}':")
      @logger.info(e.message)
    rescue => e
      @logger.error("Error running '#{action_name}':")
      @logger.info(e.message)
      raise
    ensure
      check_for_updates
    end
  end
end