class Lerna::Runner

Attributes

logger[R]
state[R]
strategies[R]
strategy_selector[R]

Public Class Methods

new(logger:, strategies:, system:, state: State.new, strategy_selector: StrategySelector.new) click to toggle source
# File lib/lerna/runner.rb, line 6
def initialize(logger:, strategies:, system:, state: State.new,
               strategy_selector: StrategySelector.new)
  @logger = logger
  @strategies = strategies
  @system = system
  @state = state
  @strategy_selector = strategy_selector
end

Public Instance Methods

run() click to toggle source
# File lib/lerna/runner.rb, line 15
def run
  state.scan!
  return unless state.changed?

  logger.debug state_summary
  strategy = find_strategy
  if strategy
    logger.info "Using #{strategy.class}"
    apply_strategy strategy
  else
    logger.warn 'No applicable strategy found'
  end
end

Private Instance Methods

apply_strategy(strategy) click to toggle source
# File lib/lerna/runner.rb, line 43
def apply_strategy(strategy)
  system 'xrandr', *strategy.preconfigure
  system 'xrandr', *strategy.configure
  system 'xset dpms force on'
end
find_strategy() click to toggle source
# File lib/lerna/runner.rb, line 39
def find_strategy
  strategy_selector.call(strategies, state.displays)
end
state_summary() click to toggle source
# File lib/lerna/runner.rb, line 33
def state_summary
  state.displays.
    map { |d| "#{d.name}#{d.connected? ? '*' : ''}" }.
    join(' ')
end
system(*args) click to toggle source
# File lib/lerna/runner.rb, line 49
def system(*args)
  logger.debug args.join(' ')
  @system.call(*args)
end