Sha256: 07677eda86d93d6caa5b46dcecf60e9f873ad6236d68139a3ede73a84817959b

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 Bytes

Contents

require_relative 'logger'

module Annoyme
  class ShellFileAppender
    COMMAND_TO_APPEND = 'annoyme print'

    def initialize(path)
      raise 'shellfile does not exist' unless File.exist?(path)
      @path = path
    end

    def append_command
      if command_missing?
        append_annoyme_command
        Logger.yellow('modified', @path.split('/').last)
      end
    end

    private

    def command_missing?
      File.foreach(@path) do |line|
        if line.strip == COMMAND_TO_APPEND
          return false
        end
      end

      true
    end

    def append_annoyme_command
      File.open(@path, 'a') do |f|
        f.puts "\n# so annoyme gets executed on startup"
        f.puts "annoyme print"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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