Sha256: e3ca31ef0e27702ea0715ad660c0b4765023a453caf7ac8bf1baa2ab519c9eea

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

# frozen_string_literal: true

require_relative '../helpers/os_helper.rb'

module Geet
  module Services
    class CreateGist
      include Geet::Helpers::OsHelper

      # options:
      #   :description
      #   :publik:      defaults to false
      #   :no_browse    defaults to false
      #
      def execute(repository, full_filename, description: nil, publik: false, no_browse: false, output: $stdout)
        content = IO.read(full_filename)

        gist_access = publik ? 'public' : 'private'
        output.puts "Creating a #{gist_access} gist..."

        filename = File.basename(full_filename)
        gist = repository.create_gist(filename, content, description: description, publik: publik)

        if no_browse
          output.puts "Gist address: #{gist.link}"
        else
          open_file_with_default_application(gist.link)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
geet-0.3.0 lib/geet/services/create_gist.rb
geet-0.2.1 lib/geet/services/create_gist.rb
geet-0.2.0 lib/geet/services/create_gist.rb