Class: Geet::Services::CreateGist
- Inherits:
-
Object
- Object
- Geet::Services::CreateGist
- Extended by:
- T::Sig
- Includes:
- Helpers::OsHelper
- Defined in:
- lib/geet/services/create_gist.rb
Constant Summary collapse
Instance Method Summary collapse
- #execute(full_filename, stdin: false, description: nil, publik: false, open_browser: false) ⇒ Object
-
#initialize(out: $stdout) ⇒ CreateGist
constructor
A new instance of CreateGist.
Methods included from Helpers::OsHelper
#execute_command, #open_file_with_default_application
Constructor Details
#initialize(out: $stdout) ⇒ CreateGist
Returns a new instance of CreateGist.
17 18 19 20 21 22 |
# File 'lib/geet/services/create_gist.rb', line 17 def initialize(out: $stdout) @out = T.let(out, T.any(IO, StringIO)) api_token = extract_env_api_token @api_interface = T.let(Geet::Github::ApiInterface.new(api_token), Geet::Github::ApiInterface) end |
Instance Method Details
#execute(full_filename, stdin: false, description: nil, publik: false, open_browser: false) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/geet/services/create_gist.rb', line 38 def execute(full_filename, stdin: false, description: nil, publik: false, open_browser: false) content = stdin ? $stdin.read : IO.read(full_filename) gist_access = publik ? "public" : "private" @out.puts "Creating a #{gist_access} gist..." filename = File.basename(full_filename) gist = Geet::Github::Gist.create(filename, content, @api_interface, description:, publik:) if open_browser open_file_with_default_application(gist.link) else @out.puts "Gist address: #{gist.link}" end end |