Sha256: 2bcd117432768c4ecba790d1e7676486768e604ec6cd9cc096d733a83da67d4a

Contents?: true

Size: 976 Bytes

Versions: 21

Compression:

Stored size: 976 Bytes

Contents

module Timber
  class CLI
    class FileHelper
      attr_reader :api

      def initialize(api)
        @api = api
      end

      def append(path, contents)
        File.open(path, "a") do |f|
          f.write(contents)
        end
      end

      def exists?(path)
        File.exists?(path)
      end

      def read_or_create(path, contents)
        if !exists?(path)
          write(path, contents)
        end

        read(path)
      end

      def read(path)
        File.read(path)
      end

      def write(path, contents)
        File.open(path, "w") do |f|
          f.write(contents)
        end
      end

      def verify(path, io)
        if !exists?(path)
          io.puts ""
          io.puts "Uh oh! It looks like we couldn't locate the #{path} file. "
          io.puts "Please enter the correct path:"
          io.puts

          new_path = io.gets
          verify(new_path, io)
        else
          path
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
timber-2.6.2 lib/timber/cli/file_helper.rb
timber-2.6.1 lib/timber/cli/file_helper.rb
timber-2.6.0 lib/timber/cli/file_helper.rb
timber-2.6.0.pre.beta2 lib/timber/cli/file_helper.rb
timber-2.6.0.pre.beta1 lib/timber/cli/file_helper.rb
timber-2.5.1 lib/timber/cli/file_helper.rb
timber-2.5.0 lib/timber/cli/file_helper.rb
timber-2.4.0 lib/timber/cli/file_helper.rb
timber-2.3.4 lib/timber/cli/file_helper.rb
timber-2.3.3 lib/timber/cli/file_helper.rb
timber-2.3.2 lib/timber/cli/file_helper.rb
timber-2.3.1 lib/timber/cli/file_helper.rb
timber-2.3.0 lib/timber/cli/file_helper.rb
timber-2.2.3 lib/timber/cli/file_helper.rb
timber-2.2.2 lib/timber/cli/file_helper.rb
timber-2.2.1 lib/timber/cli/file_helper.rb
timber-2.2.0 lib/timber/cli/file_helper.rb
timber-2.1.10 lib/timber/cli/file_helper.rb
timber-2.1.9 lib/timber/cli/file_helper.rb
timber-2.1.8 lib/timber/cli/file_helper.rb