gistribute 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 943e1cbafa8fcd6769fdf9e11c4770a7589335247b4232fa4f37c7720cfb3769
4
+ data.tar.gz: 1d4fe35b75840e4d8f9a2510616790fdafe9e7b216422514736f9d82943f7dc4
5
+ SHA512:
6
+ metadata.gz: 84563d81f9d47098a8a6a48b64c20a606f0831a34cf2d9fc3b150c0dd6e25cc9728103e0e3e7648a5e154f81c1ddc7ac2a7670d8d753689693f9d6f4b966dc52
7
+ data.tar.gz: ad01c45e1e7adcd4650ac23fcf0ed6c3f72112837639874350a3a22e1bc655e1369e26341d11b5d9a388d89e2e5f525697474235a7f503e16d08f63879be70ca
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2012 Vinny Diehl
1
+ Copyright (C) 2012-2023 Vinny Diehl
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -11,7 +11,9 @@ a tweak to one of the files that you're sharing.
11
11
 
12
12
  ## Installation
13
13
 
14
- $ gem install gistribute
14
+ ```sh
15
+ gem install gistribute
16
+ ```
15
17
 
16
18
  ## How It Works
17
19
 
@@ -38,7 +40,7 @@ If the resulting Gist link was, for example, https://gist.github.com/123456,
38
40
  the user would be able to run either of these commands to download the file
39
41
  to `~/.vimrc`:
40
42
 
41
- ```Shell
42
- $ gistribute 123456
43
- $ gistribute https://gist.github.com/123456
43
+ ```sh
44
+ gistribute 123456
45
+ gistribute https://gist.github.com/123456
44
46
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1
1
+ 0.2
data/bin/gistribute CHANGED
@@ -1,27 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "colorize"
4
+ require "fileutils"
5
+ require "json"
6
+ require "open-uri"
7
+
8
+ # Print to STDOUT to clear line
9
+ CLEAR = "\r\e[K"
10
+
3
11
  if %w[-v --version].include? ARGV.first
4
12
  puts "Gistribute #{File.read(File.expand_path("../../VERSION", __FILE__)).strip}"
5
13
  exit 0
6
14
  end
7
15
 
8
- require "json"
9
- require "fileutils"
10
- require "open-uri"
11
- require "nutella"
12
-
13
16
  print "Downloading data..."
14
17
 
15
18
  # The user can pass in either just the ID or the entire URL to the Gist.
16
19
  id = ARGV.first[/(^|\/)([[:xdigit:]]+)/, 2]
17
20
 
18
21
  begin
19
- gist = JSON.parse open("https://api.github.com/gists/#{id}").read
22
+ gist = JSON.parse(URI.open("https://api.github.com/gists/#{id}").read)
20
23
  rescue OpenURI::HTTPError => msg
21
- print <<-EOS.heredoc.red
22
-
23
-
24
- There was an error downloading the requested Gist.
24
+ print <<~EOS.red
25
+ #{CLEAR}There was an error downloading the requested Gist.
25
26
  The error is as follows:
26
27
  EOS
27
28
  puts msg
@@ -39,8 +40,8 @@ end
39
40
  # "html_url" => "Link to the Gist",
40
41
  # "description" => "The description for the Gist",
41
42
  #
42
- # "user" => nil, # IF ANONYMOUS
43
- # "user" => { # IF TIED TO A USER
43
+ # "owner" => nil, # IF ANONYMOUS
44
+ # "owner" => { # IF TIED TO A USER
44
45
  # "login" => "username"
45
46
  # },
46
47
  #
@@ -58,14 +59,13 @@ end
58
59
  desc = gist["description"].gsub(/(.{1,79})(\s+|\Z)/, "\\1\n").strip
59
60
  desc = "\n#{desc}\n" unless desc.empty?
60
61
 
61
- puts <<EOS
62
- \n
63
- Finished downloading Gist from: #{gist["html_url"]}
64
- Gist uploaded by #{
65
- gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
66
- }.
67
- #{desc}
68
- Beginning install...
62
+ puts <<~EOS
63
+ #{CLEAR}Finished downloading Gist from: #{gist["html_url"]}
64
+ Gist uploaded by #{
65
+ gist["owner"] ? "user #{gist["owner"]["login"]}" : "an anonymous user"
66
+ }.
67
+ #{desc}
68
+ Beginning install...
69
69
  EOS
70
70
 
71
71
  gist["files"].each do |filename, data|
@@ -73,7 +73,7 @@ gist["files"].each do |filename, data|
73
73
 
74
74
  # | as path separator in the Gist's file name, as Gist doesn't allow the
75
75
  # usage of /.
76
- path = metadata.last.gsub /[~|]/, "|" => "/", "~" => Dir.home
76
+ path = metadata.last.gsub(/[~|]/, "|" => "/", "~" => Dir.home)
77
77
  # Default description is the name of the file.
78
78
  description = metadata.size == 1 ? File.basename(path) : metadata.first
79
79
 
@@ -82,5 +82,5 @@ gist["files"].each do |filename, data|
82
82
  # Handle directories that don't exist.
83
83
  FileUtils.mkdir_p File.dirname(path)
84
84
 
85
- File.write path, data["content"]
85
+ File.write(path, data["content"])
86
86
  end
data/gistribute.gemspec CHANGED
@@ -14,10 +14,12 @@ Gem::Specification.new do |gem|
14
14
  gem.bindir = "bin"
15
15
  gem.executables = %w[gistribute]
16
16
 
17
- gem.files = Dir["bin/**/*"] + %w[
17
+ gem.test_files = Dir["spec/**/*"]
18
+ gem.files = Dir["bin/**/*"] + gem.test_files + %w[
18
19
  LICENSE Rakefile README.md VERSION gistribute.gemspec
19
20
  ]
20
21
 
21
- gem.add_dependency "json", "~> 1.7"
22
- gem.add_dependency "nutella", "~> 0.11"
22
+ gem.add_dependency "colorize", "~> 1.0"
23
+ gem.add_development_dependency "fuubar", "~> 2.0"
24
+ gem.add_development_dependency "rspec", "~> 3.12"
23
25
  end
@@ -0,0 +1,33 @@
1
+ require "fileutils"
2
+
3
+ TEMP = "/tmp/gistribute_spec"
4
+
5
+ describe "gistribute" do
6
+ # Make sure we start and end with a clean `/tmp`
7
+ before { FileUtils.rm_rf TEMP }
8
+ after { FileUtils.rm_rf TEMP }
9
+
10
+ BAD_LINK = "bad_link"
11
+ let(:output_404) { `gistribute #{BAD_LINK}` }
12
+
13
+ let(:output) { `gistribute https://gist.github.com/4346763` }
14
+ let(:output_only_id) { `gistribute 4346763` }
15
+
16
+ let :version do
17
+ File.read(File.expand_path("../../VERSION", __FILE__)).strip
18
+ end
19
+
20
+ %w[--version -v].each do |flag|
21
+ context "with the #{flag} flag" do
22
+ it "outputs the version" do
23
+ expect(`gistribute #{flag}`).to eq "Gistribute #{version}\n"
24
+ end
25
+ end
26
+ end
27
+
28
+ context "with a single file Gist" do
29
+ it "allows both the full URL and the Gist ID" do
30
+ expect(output).to eq output_only_id
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistribute
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
5
- prerelease:
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vinny Diehl
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
11
+ date: 2023-07-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: json
14
+ name: colorize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '1.7'
19
+ version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.7'
26
+ version: '1.0'
30
27
  - !ruby/object:Gem::Dependency
31
- name: nutella
28
+ name: fuubar
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0.11'
38
- type: :runtime
33
+ version: '2.0'
34
+ type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0.11'
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
46
55
  description: Distribute files simply using GitHub Gist.
47
56
  email: vinny.diehl@gmail.com
48
57
  executables:
@@ -50,36 +59,35 @@ executables:
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - bin/gistribute
54
62
  - LICENSE
55
- - Rakefile
56
63
  - README.md
64
+ - Rakefile
57
65
  - VERSION
66
+ - bin/gistribute
58
67
  - gistribute.gemspec
68
+ - spec/gistribute_spec.rb
59
69
  homepage: https://github.com/gbchaosmaster/gistribute
60
70
  licenses:
61
71
  - MIT
62
- post_install_message:
72
+ metadata: {}
73
+ post_install_message:
63
74
  rdoc_options: []
64
75
  require_paths:
65
76
  - lib
66
77
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
78
  requirements:
69
- - - ! '>='
79
+ - - ">="
70
80
  - !ruby/object:Gem::Version
71
81
  version: '0'
72
82
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
83
  requirements:
75
- - - ! '>='
84
+ - - ">="
76
85
  - !ruby/object:Gem::Version
77
86
  version: '0'
78
87
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 1.8.24
81
- signing_key:
82
- specification_version: 3
88
+ rubygems_version: 3.4.17
89
+ signing_key:
90
+ specification_version: 4
83
91
  summary: GitHub Gist based file distribution.
84
- test_files: []
85
- has_rdoc:
92
+ test_files:
93
+ - spec/gistribute_spec.rb