gistribute 0.0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,46 +11,36 @@ 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
 
18
- Gistribute looks at the files in each Gist and checks for one or two lines of
19
- metadata at the top of the file. The metadata must begin with ```%%```, but
20
- you may put anything before that and it won't be parsed.
21
-
22
- The first line of metadata contains the location on the client's computer that
23
- you wish to install the file to. The second contains the name of the file as it
24
- will be printed on the user's screen as it is installed. If the second line is
25
- excluded, Gistribute will use the name of the file in the Gist.
20
+ Gistribute looks at the filename that you enter on Gist to find all of the
21
+ data that it needs to download the file to the other user's computer. It
22
+ allows you to choose what Gistribute will call the file when it is installing
23
+ it, and where it will install the file.
26
24
 
27
25
  ## Usage
28
26
 
29
- An example follows:
27
+ If, for example, you were sharing a .vimrc file, and you wanted Gistribute to
28
+ call it "Vim configuration" when it was installing it, you would name the file
29
+ `Vim configuration||~|.vimrc`. If the filename contains the sequence `||`,
30
+ anything before that will be considered the description of that file, and
31
+ anything after it the installation path. If there is no `||`, Gistribute will
32
+ use the name of the file (without the path to it) as the default description.
30
33
 
31
- ```VimL
32
- "%% ~/.vimrc
33
- "%% Vim configuration
34
- " This is an example .vimrc file being shared via Gistribute.
35
- " Notice the two comments at the top containing the metadata.
36
-
37
- set nocompatible
38
- filetype indent plugin on
39
- syntax on
40
- ```
34
+ The file path separator is the pipe character because GitHub Gist doesn't
35
+ allow slashes in filenames- this quirk is the result of Gist actually saving
36
+ those files to a Git repository on their servers, and handling slashes in
37
+ file names can't possibly be very nice.
41
38
 
42
- If, for example, the resulting Gist link was https://gist.github.com/123456,
39
+ If the resulting Gist link was, for example, https://gist.github.com/123456,
43
40
  the user would be able to run either of these commands to download the file
44
- to ```~/.vimrc```:
41
+ to `~/.vimrc`:
45
42
 
46
- $ gistribute 123456
47
- $ gistribute https://gist.github.com/123456
48
-
49
- **Gistribute will strip the metadata from the files.** Don't worry about having
50
- messy files on the user's computer because of the metadata sitting at the top,
51
- as this is taken care of. Be aware, however, that if you leave a blank line
52
- between the metadata and the first line of the file, the resulting downloaded
53
- file **will** have a blank line at the top.
54
-
55
- If there are files in the Gist without metadata, they will be ignored by
56
- Gistribute.
43
+ ```sh
44
+ gistribute 123456
45
+ gistribute https://gist.github.com/123456
46
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.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 "open-uri"
10
- require "colorize"
11
- require "nutella"
12
-
13
16
  print "Downloading data..."
14
17
 
15
- # The user can paste in either just the ID or the entire URL to the Gist.
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
  #
@@ -52,38 +53,34 @@ end
52
53
  # }
53
54
  # }
54
55
 
55
- puts <<-EOS.heredoc
56
-
56
+ # Regular expression word wrap to keep lines less than 80 characters. Then
57
+ # check to see if it's empty- if not, put newlines on each side so that it
58
+ # will be padded when displayed in the output.
59
+ desc = gist["description"].gsub(/(.{1,79})(\s+|\Z)/, "\\1\n").strip
60
+ desc = "\n#{desc}\n" unless desc.empty?
57
61
 
58
- Finished downloading Gist from: #{gist["html_url"]}
62
+ puts <<~EOS
63
+ #{CLEAR}Finished downloading Gist from: #{gist["html_url"]}
59
64
  Gist uploaded by #{
60
- gist["user"] ? "user #{gist["user"]["login"]}" : "an anonymous user"
65
+ gist["owner"] ? "user #{gist["owner"]["login"]}" : "an anonymous user"
61
66
  }.
62
-
67
+ #{desc}
63
68
  Beginning install...
64
69
  EOS
65
70
 
66
71
  gist["files"].each do |filename, data|
67
- lines = data["content"].lines.to_a
68
-
69
- # Parse out all metadata after %% on the first two lines, strip out
70
- # (lead|trail)ing whitespace while we're at it.
71
- metadata = lines[0..1].map { |line| line[/%%\s*(.*\S)\s*/, 1] }
72
-
73
- # Skip non-Gistribute files.
74
- next if metadata.first.nil?
72
+ metadata = filename.split("||").map &:strip
75
73
 
76
- puts " #{"*".green} Installing #{metadata[1] || filename}..."
74
+ # | as path separator in the Gist's file name, as Gist doesn't allow the
75
+ # usage of /.
76
+ path = metadata.last.gsub(/[~|]/, "|" => "/", "~" => Dir.home)
77
+ # Default description is the name of the file.
78
+ description = metadata.size == 1 ? File.basename(path) : metadata.first
77
79
 
78
- # TODO: Is there a better way to handle ~?
79
- path = metadata.first.gsub "~", Dir.home
80
+ puts " #{"*".green} Installing #{description}..."
80
81
 
81
82
  # Handle directories that don't exist.
82
83
  FileUtils.mkdir_p File.dirname(path)
83
84
 
84
- File.open(path, "w") do |f|
85
- # Remove all lines with metadata- lines that don't match will return nil,
86
- # so compact it and drop that many off the top of the file.
87
- f << lines[metadata.compact.size..-1].join
88
- end
85
+ File.write(path, data["content"])
89
86
  end
data/gistribute.gemspec CHANGED
@@ -14,11 +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.10"
23
- gem.add_dependency "colorize", "~> 0.5"
22
+ gem.add_dependency "colorize", "~> 1.0"
23
+ gem.add_development_dependency "fuubar", "~> 2.0"
24
+ gem.add_development_dependency "rspec", "~> 3.12"
24
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,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.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-06 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.10'
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.10'
40
+ version: '2.0'
46
41
  - !ruby/object:Gem::Dependency
47
- name: colorize
42
+ name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '0.5'
54
- type: :runtime
47
+ version: '3.12'
48
+ type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
- version: '0.5'
54
+ version: '3.12'
62
55
  description: Distribute files simply using GitHub Gist.
63
56
  email: vinny.diehl@gmail.com
64
57
  executables:
@@ -66,36 +59,35 @@ executables:
66
59
  extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
- - bin/gistribute
70
62
  - LICENSE
71
- - Rakefile
72
63
  - README.md
64
+ - Rakefile
73
65
  - VERSION
66
+ - bin/gistribute
74
67
  - gistribute.gemspec
68
+ - spec/gistribute_spec.rb
75
69
  homepage: https://github.com/gbchaosmaster/gistribute
76
70
  licenses:
77
71
  - MIT
78
- post_install_message:
72
+ metadata: {}
73
+ post_install_message:
79
74
  rdoc_options: []
80
75
  require_paths:
81
76
  - lib
82
77
  required_ruby_version: !ruby/object:Gem::Requirement
83
- none: false
84
78
  requirements:
85
- - - ! '>='
79
+ - - ">="
86
80
  - !ruby/object:Gem::Version
87
81
  version: '0'
88
82
  required_rubygems_version: !ruby/object:Gem::Requirement
89
- none: false
90
83
  requirements:
91
- - - ! '>='
84
+ - - ">="
92
85
  - !ruby/object:Gem::Version
93
86
  version: '0'
94
87
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 1.8.24
97
- signing_key:
98
- specification_version: 3
88
+ rubygems_version: 3.4.17
89
+ signing_key:
90
+ specification_version: 4
99
91
  summary: GitHub Gist based file distribution.
100
- test_files: []
101
- has_rdoc:
92
+ test_files:
93
+ - spec/gistribute_spec.rb