lib/balboa/interactor/capybara_interactor.rb in balboa-0.1.1 vs lib/balboa/interactor/capybara_interactor.rb in balboa-0.1.2

- old
+ new

@@ -1,31 +1,46 @@ # frozen_string_literal: true module Balboa module Interactor class CapybaraInteractor - def initialize(options) - @options = options - @commands = {} + + CommandNotFound = Class.new(RuntimeError) + LoginCommandNotFound = Class.new(CommandNotFound) + + def initialize + @commands = Hash.new { fail CommandNotFound } + @signed_in = false end def add_command(key, command) @commands[key.to_s] = command end - def last_punch - login - @commands['last_punch'].execute + def last + login unless signed_in? + + @commands['last'].execute end def punch(date) - @commands['make_punch'].execute(date) + login unless signed_in? + + @commands['punch'].execute(date) end private + attr_accessor :signed_in + + alias_method :signed_in?, :signed_in + def login @commands['login'].execute + + @signed_in = true + rescue CommandNotFound + raise LoginCommandNotFound end end end end