Sha256: 9b8f4629a3159b0b072db66fe2cb3d7a1e07d07e23d1d07a1f053c123cd90593

Contents?: true

Size: 928 Bytes

Versions: 2

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module Balboa
  module Interactor
    class CapybaraInteractor

      CommandNotFound = Class.new(RuntimeError)

      LoginCommandNotFound = Class.new(RuntimeError)

      attr_reader :options

      def initialize(options={})
        @options = options
        @commands = Hash.new { fail CommandNotFound }
        @signed_in = false
      end
      
      def add_command(key, command)
        @commands[key.to_s] = command
      end

      def last
        login unless signed_in?
        @commands['last'].execute
      end

      def punch(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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
balboa-0.1.4 lib/balboa/interactor/capybara_interactor.rb
balboa-0.1.3 lib/balboa/interactor/capybara_interactor.rb