Sha256: 3345b6f6cc348da73bbbe35ae930e662c8c09953cc41f9cac57481a4bbc062ca

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require_relative 'logger'
require_relative 'shell_file_appender'
require_relative 'error/shell_not_supported_error'

module Annoyme
  class Initializer
    def initialize(file)
      @notes_file = file
      detect_shell
    end

    def perform
      create_annoyme_file
      add_annoyme_print_to_shell_file
    end

    private

    def detect_shell
      case ENV['SHELL']
      when '/bin/bash'
        @shell = :bash
        @file = File.join(ENV['HOME'], '.bashrc')
      when '/bin/zsh'
        @shell = :zsh
        @file = File.join(ENV['HOME'], '.zshrc')
      else
        raise Error::ShellNotSupportedError, 'Your shell is not supported by annoyme. You can submit an issue at the github page'
      end
    end

    def create_annoyme_file
      if @notes_file.exists?
        Logger.red('replaced', '.annoyme')
      else
        Logger.green('created', '.annoyme')
      end

      @notes_file.create
    end

    def add_annoyme_print_to_shell_file
      appender = ShellFileAppender.new(@file)
      appender.append_command
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
annoyme-1.0.0 lib/annoyme/initializer.rb