shard 0.1.1 → 0.2.0
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.
- data/bin/shard +0 -1
- data/lib/shard.rb +21 -9
- data/lib/shard/cli.rb +17 -66
- data/lib/shard/cli/commands.rb +102 -0
- data/lib/shard/cli/config.rb +102 -0
- data/lib/shard/cli/fork.rb +73 -0
- data/lib/shard/cli/list.rb +46 -0
- data/lib/shard/credentials.rb +61 -0
- data/lib/shard/lister.rb +1 -3
- data/lib/shard/loader.rb +10 -53
- data/lib/shard/ref.rb +38 -0
- data/lib/shard/saver.rb +16 -12
- data/lib/shard/shard_directory.rb +22 -18
- metadata +50 -12
- data/lib/shard/shard_record.rb +0 -29
data/bin/shard
CHANGED
data/lib/shard.rb
CHANGED
@@ -1,13 +1,25 @@
|
|
1
1
|
class Shard
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
def self.api
|
4
|
+
@api ||= Octokit::Client.new netrc: (Credentials.saved? && Credentials.valid?)
|
4
5
|
end
|
6
|
+
|
7
|
+
def self.Ref(shard_line)
|
8
|
+
case shard_line
|
9
|
+
when String then Shard::Ref.parse(shard_line)
|
10
|
+
when Shard::Ref then shard_line
|
11
|
+
else raise ArgumentError
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'shard/credentials'
|
16
|
+
require 'shard/shard_directory'
|
17
|
+
require 'shard/loader'
|
18
|
+
require 'shard/saver'
|
19
|
+
require 'shard/lister'
|
20
|
+
require 'shard/gist'
|
21
|
+
require 'shard/ref'
|
22
|
+
require 'shard/kernel'
|
23
|
+
|
5
24
|
end
|
6
25
|
|
7
|
-
require 'shard/shard_directory'
|
8
|
-
require 'shard/loader'
|
9
|
-
require 'shard/saver'
|
10
|
-
require 'shard/lister'
|
11
|
-
require 'shard/gist'
|
12
|
-
require 'shard/shard_record'
|
13
|
-
require 'shard/kernel'
|
data/lib/shard/cli.rb
CHANGED
@@ -1,72 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
module Shard::CLI
|
2
|
+
|
3
|
+
require 'shard/cli/commands'
|
4
|
+
require 'shard/cli/config'
|
5
|
+
require 'shard/cli/list'
|
6
|
+
require 'shard/cli/fork'
|
7
|
+
|
8
|
+
##################
|
9
|
+
# #
|
10
|
+
# Module Methods #
|
11
|
+
# #
|
12
|
+
##################
|
12
13
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts "Shards for Github user #{ username }:"
|
18
|
-
puts
|
19
|
-
|
20
|
-
lister.shard_names.each do |name|
|
21
|
-
shard = lister.shards[name]
|
22
|
-
puts "#{ name }:"
|
23
|
-
puts " Description | #{ shard.description }"
|
24
|
-
puts " URL | #{ shard.url }"
|
25
|
-
puts
|
26
|
-
end
|
27
|
-
else
|
28
|
-
puts "Github user #{ username } does not have any shards."
|
29
|
-
puts "Shards are gists that have a file named shard.rb or <foo>.shard.rb"
|
14
|
+
def self.start(args)
|
15
|
+
if Shard::Ref.valid?(args[0])
|
16
|
+
args << "exec" if args.length == 1
|
17
|
+
args[0], args[1] = args[1], args[0]
|
30
18
|
end
|
31
|
-
end
|
32
|
-
|
33
|
-
########
|
34
|
-
# #
|
35
|
-
# Exec #
|
36
|
-
# #
|
37
|
-
########
|
38
|
-
|
39
|
-
desc "exec USERNAME/SHARD", "Runs the shard named SHARD for Github user USERNAME"
|
40
|
-
|
41
|
-
def exec(shard_line)
|
42
|
-
Shard::Loader.load shard_line
|
43
|
-
end
|
44
|
-
|
45
|
-
#########
|
46
|
-
# #
|
47
|
-
# Fetch #
|
48
|
-
# #
|
49
|
-
#########
|
50
|
-
|
51
|
-
desc "fetch USERNAME/SHARD", "Downloads the shard named SHARD for Github user USERNAME"
|
52
|
-
|
53
|
-
def fetch(shard_line)
|
54
|
-
username, shard = shard_line.split '/'
|
55
|
-
shard = Shard::ShardRecord.new(username, shard, 'HEAD')
|
56
|
-
|
57
|
-
Shard::Saver.save(shard, verbose: true)
|
58
|
-
end
|
59
|
-
|
60
|
-
########
|
61
|
-
# #
|
62
|
-
# Test #
|
63
|
-
# #
|
64
|
-
########
|
65
|
-
|
66
|
-
desc "test USERNAME/SHARD", "Runs the tests for shard named SHARD for Github user USERNAME"
|
67
19
|
|
68
|
-
|
69
|
-
Shard::Loader.test shard_line
|
20
|
+
Commands.start(args)
|
70
21
|
end
|
71
22
|
|
72
23
|
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Shard::CLI
|
4
|
+
|
5
|
+
class Commands < Thor
|
6
|
+
|
7
|
+
########
|
8
|
+
# #
|
9
|
+
# List #
|
10
|
+
# #
|
11
|
+
########
|
12
|
+
|
13
|
+
desc "list USERNAME", "List all shards for Github user USERNAME"
|
14
|
+
|
15
|
+
def list(username)
|
16
|
+
Shard::CLI::List.run(username)
|
17
|
+
end
|
18
|
+
|
19
|
+
########
|
20
|
+
# #
|
21
|
+
# Exec #
|
22
|
+
# #
|
23
|
+
########
|
24
|
+
|
25
|
+
desc "USERNAME/SHARD", "Runs the shard named SHARD for Github user USERNAME"
|
26
|
+
|
27
|
+
def exec(shard_line)
|
28
|
+
Shard::Loader.load shard_line
|
29
|
+
end
|
30
|
+
|
31
|
+
#########
|
32
|
+
# #
|
33
|
+
# Fetch #
|
34
|
+
# #
|
35
|
+
#########
|
36
|
+
|
37
|
+
desc "USERNAME/SHARD fetch", "Downloads the shard named SHARD for Github user USERNAME"
|
38
|
+
|
39
|
+
def fetch(shard_line)
|
40
|
+
Shard::Saver.save shard_line, verbose: true
|
41
|
+
end
|
42
|
+
|
43
|
+
########
|
44
|
+
# #
|
45
|
+
# Test #
|
46
|
+
# #
|
47
|
+
########
|
48
|
+
|
49
|
+
desc "USERNAME/SHARD test", "Runs the tests for shard named SHARD for Github user USERNAME"
|
50
|
+
|
51
|
+
def test(shard_line)
|
52
|
+
Shard::Loader.test shard_line
|
53
|
+
end
|
54
|
+
|
55
|
+
##########
|
56
|
+
# #
|
57
|
+
# Config #
|
58
|
+
# #
|
59
|
+
##########
|
60
|
+
|
61
|
+
desc "config", "Set up Github credentials for use in shard"
|
62
|
+
|
63
|
+
def config
|
64
|
+
Shard::CLI::Config.run
|
65
|
+
end
|
66
|
+
|
67
|
+
########
|
68
|
+
# #
|
69
|
+
# View #
|
70
|
+
# #
|
71
|
+
########
|
72
|
+
|
73
|
+
desc "USERNAME/SHARD view", "Opens the shard in a browser window"
|
74
|
+
|
75
|
+
def view(shard_line)
|
76
|
+
if line = Shard::Ref.parse(shard_line)
|
77
|
+
lister = Shard::Lister.new(line.user)
|
78
|
+
shard = lister.shards[line.name]
|
79
|
+
url = shard.url
|
80
|
+
|
81
|
+
`open #{ url }`
|
82
|
+
else
|
83
|
+
puts "'#{ shard_line }' is not a valid shard reference."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
########
|
88
|
+
# #
|
89
|
+
# Fork #
|
90
|
+
# #
|
91
|
+
########
|
92
|
+
|
93
|
+
desc "USERNAME/SHARD fork", "Forks a copy of the shard into your Github account (requires authentication)"
|
94
|
+
|
95
|
+
def fork(shard_line)
|
96
|
+
Shard::CLI::Fork.run shard_line
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'io/console'
|
2
|
+
|
3
|
+
module Shard::CLI
|
4
|
+
|
5
|
+
class Config
|
6
|
+
|
7
|
+
#################
|
8
|
+
# #
|
9
|
+
# Class Methods #
|
10
|
+
# #
|
11
|
+
#################
|
12
|
+
|
13
|
+
def self.run
|
14
|
+
new.run
|
15
|
+
end
|
16
|
+
|
17
|
+
####################
|
18
|
+
# #
|
19
|
+
# Instance Methods #
|
20
|
+
# #
|
21
|
+
####################
|
22
|
+
|
23
|
+
def run
|
24
|
+
if credentials_saved?
|
25
|
+
replace_credentials
|
26
|
+
else
|
27
|
+
add_credentials
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def add_credentials
|
34
|
+
puts <<-EOF
|
35
|
+
To use shard features that require a Github login,
|
36
|
+
please enter your username and password below.
|
37
|
+
|
38
|
+
Note, you can provide an Personal Access Token instead
|
39
|
+
of a password (recommended).
|
40
|
+
(See https://github.com/settings/tokens/new for more information)
|
41
|
+
|
42
|
+
EOF
|
43
|
+
|
44
|
+
print " Username | "
|
45
|
+
username = STDIN.gets.to_s.chomp
|
46
|
+
print " Password | "
|
47
|
+
password = STDIN.noecho(&:gets).to_s.chomp
|
48
|
+
|
49
|
+
save_credentials(username, password)
|
50
|
+
|
51
|
+
if credentials_saved?
|
52
|
+
puts "\nCredentials saved to ~/.netrc"
|
53
|
+
|
54
|
+
validate_login
|
55
|
+
else
|
56
|
+
puts "\nCredentials have been cleared."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def credentials_saved?
|
61
|
+
Shard::Credentials.saved?
|
62
|
+
end
|
63
|
+
|
64
|
+
def replace_credentials
|
65
|
+
str = valid_login? ? "" : "invalid "
|
66
|
+
|
67
|
+
puts "You currently have #{ str }Github credentials saved in ~/.netrc"
|
68
|
+
print "Do you wish to replace them? [yn] "
|
69
|
+
|
70
|
+
if yes?
|
71
|
+
add_credentials
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def save_credentials(username, password)
|
76
|
+
Shard::Credentials.new(username, password).save
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_login
|
80
|
+
if valid_login?
|
81
|
+
puts "\nThe saved Github credentials are valid."
|
82
|
+
else
|
83
|
+
puts "\nThe saved Github credentials are invalid."
|
84
|
+
print "Do you wish to re-enter them? [yn] "
|
85
|
+
|
86
|
+
if yes?
|
87
|
+
add_credentials
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_login?
|
93
|
+
Shard::Credentials.valid?
|
94
|
+
end
|
95
|
+
|
96
|
+
def yes?
|
97
|
+
STDIN.gets.chomp.downcase == 'y'
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Shard::CLI
|
2
|
+
|
3
|
+
class Fork
|
4
|
+
|
5
|
+
################
|
6
|
+
# #
|
7
|
+
# Declarations #
|
8
|
+
# #
|
9
|
+
################
|
10
|
+
|
11
|
+
attr_reader :ref
|
12
|
+
|
13
|
+
###############
|
14
|
+
# #
|
15
|
+
# Constructor #
|
16
|
+
# #
|
17
|
+
###############
|
18
|
+
|
19
|
+
def initialize(shard_line)
|
20
|
+
@ref = Shard::Ref(shard_line)
|
21
|
+
end
|
22
|
+
|
23
|
+
#################
|
24
|
+
# #
|
25
|
+
# Class Methods #
|
26
|
+
# #
|
27
|
+
#################
|
28
|
+
|
29
|
+
def self.run(shard_line)
|
30
|
+
new(shard_line).run
|
31
|
+
end
|
32
|
+
|
33
|
+
####################
|
34
|
+
# #
|
35
|
+
# Instance Methods #
|
36
|
+
# #
|
37
|
+
####################
|
38
|
+
|
39
|
+
def run
|
40
|
+
if ref.nil?
|
41
|
+
puts "That is not a valid shard reference."
|
42
|
+
return
|
43
|
+
end
|
44
|
+
|
45
|
+
if Shard::Credentials.saved? && Shard::Credentials.valid?
|
46
|
+
fork_shard
|
47
|
+
else
|
48
|
+
puts "You are not currently logged into Github."
|
49
|
+
Shard::CLI::Config.run
|
50
|
+
|
51
|
+
if Shard::Credentials.saved?
|
52
|
+
run
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def fork_shard
|
60
|
+
lister = Shard::Lister.new(ref.user)
|
61
|
+
shard = lister.shards[ref.name]
|
62
|
+
|
63
|
+
if shard
|
64
|
+
puts "Forking #{ ref.user }/#{ ref.name }..."
|
65
|
+
Shard.api.fork_gist(shard.id)
|
66
|
+
else
|
67
|
+
puts "That is not a valid shard reference."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Shard::CLI
|
2
|
+
|
3
|
+
class List
|
4
|
+
|
5
|
+
#################
|
6
|
+
# #
|
7
|
+
# Class Methods #
|
8
|
+
# #
|
9
|
+
#################
|
10
|
+
|
11
|
+
def self.run(username)
|
12
|
+
new.run(username)
|
13
|
+
end
|
14
|
+
|
15
|
+
####################
|
16
|
+
# #
|
17
|
+
# Instance Methods #
|
18
|
+
# #
|
19
|
+
####################
|
20
|
+
|
21
|
+
def run(username)
|
22
|
+
lister = Shard::Lister.new(username)
|
23
|
+
|
24
|
+
if lister.shards.any?
|
25
|
+
puts "Shards for Github user #{ username }:"
|
26
|
+
puts
|
27
|
+
|
28
|
+
lister.shard_names.each do |name|
|
29
|
+
shard = lister.shards[name]
|
30
|
+
puts "#{ name }:"
|
31
|
+
puts " Description | #{ shard.description }"
|
32
|
+
puts " URL | #{ shard.url }"
|
33
|
+
puts
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "Github user #{ username } does not have any shards."
|
37
|
+
puts "Shards are gists that have a file named shard.rb or <foo>.shard.rb"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
require 'netrc'
|
3
|
+
|
4
|
+
class Shard
|
5
|
+
|
6
|
+
class Credentials < Struct.new(:username, :password)
|
7
|
+
|
8
|
+
################
|
9
|
+
# #
|
10
|
+
# Declarations #
|
11
|
+
# #
|
12
|
+
################
|
13
|
+
|
14
|
+
GITHUB_API_ENTRY = "api.github.com"
|
15
|
+
|
16
|
+
#################
|
17
|
+
# #
|
18
|
+
# Class Methods #
|
19
|
+
# #
|
20
|
+
#################
|
21
|
+
|
22
|
+
def self.current
|
23
|
+
username, password = Netrc.read[GITHUB_API_ENTRY]
|
24
|
+
new(username, password)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.saved?
|
28
|
+
current.present?
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.valid?
|
32
|
+
Octokit.validate_credentials netrc: true
|
33
|
+
end
|
34
|
+
|
35
|
+
####################
|
36
|
+
# #
|
37
|
+
# Instance Methods #
|
38
|
+
# #
|
39
|
+
####################
|
40
|
+
|
41
|
+
def save
|
42
|
+
if present?
|
43
|
+
netrc_file[GITHUB_API_ENTRY] = username, password
|
44
|
+
else
|
45
|
+
netrc_file.delete GITHUB_API_ENTRY
|
46
|
+
end
|
47
|
+
|
48
|
+
netrc_file.save
|
49
|
+
end
|
50
|
+
|
51
|
+
def netrc_file
|
52
|
+
@netrc_file ||= Netrc.read
|
53
|
+
end
|
54
|
+
|
55
|
+
def present?
|
56
|
+
!(username.to_s == '' || password.to_s == '')
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
data/lib/shard/lister.rb
CHANGED
data/lib/shard/loader.rb
CHANGED
@@ -10,9 +10,10 @@ class Shard
|
|
10
10
|
|
11
11
|
include ShardDirectory
|
12
12
|
|
13
|
-
|
13
|
+
SHARD_FILE_PATTERN = %q(*shard.rb)
|
14
|
+
TEST_FILE_PATTERNS = %w( *_spec.rb *_test.rb )
|
14
15
|
|
15
|
-
|
16
|
+
attr_reader :ref
|
16
17
|
|
17
18
|
###############
|
18
19
|
# #
|
@@ -21,7 +22,7 @@ class Shard
|
|
21
22
|
###############
|
22
23
|
|
23
24
|
def initialize(shard_line)
|
24
|
-
|
25
|
+
@ref = Shard::Ref(shard_line)
|
25
26
|
end
|
26
27
|
|
27
28
|
#################
|
@@ -45,69 +46,25 @@ class Shard
|
|
45
46
|
####################
|
46
47
|
|
47
48
|
def load
|
48
|
-
|
49
|
-
|
50
|
-
Shard.current_loader, previous_loader = self, Shard.current_loader
|
51
|
-
require shard_file_path
|
52
|
-
Shard.current_loader = previous_loader
|
49
|
+
load_file(SHARD_FILE_PATTERN)
|
53
50
|
end
|
54
51
|
|
55
52
|
def load_file(filename)
|
56
|
-
|
57
|
-
|
53
|
+
ensure_shard_saved
|
54
|
+
|
55
|
+
require find_file_path(ref, filename)
|
58
56
|
end
|
59
57
|
|
60
58
|
def test
|
61
59
|
ensure_shard_saved
|
62
60
|
|
63
|
-
|
64
|
-
require *shard_test_paths
|
65
|
-
Shard.current_loader = previous_loader
|
61
|
+
require *find_file_paths(ref, *TEST_FILE_PATTERNS)
|
66
62
|
end
|
67
63
|
|
68
64
|
private
|
69
65
|
|
70
|
-
def already_loaded?
|
71
|
-
shard_dir_exists?(shard.username, shard.name, shard.version)
|
72
|
-
end
|
73
|
-
|
74
66
|
def ensure_shard_saved
|
75
|
-
|
76
|
-
Shard::Saver.save shard
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def parse_shard_line(shard_line)
|
81
|
-
if match = shard_line.match(SHARD_LINE_REGEX)
|
82
|
-
username = match[1]
|
83
|
-
name = match[2]
|
84
|
-
version = parse_version match[3]
|
85
|
-
|
86
|
-
@shard = Shard::ShardRecord.new(username, name, version)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def parse_version(raw_version)
|
91
|
-
raw_version || 'HEAD'
|
92
|
-
end
|
93
|
-
|
94
|
-
def ruby_file_path(filename)
|
95
|
-
file_path(shard.username, shard.name, shard.version, filename)
|
96
|
-
end
|
97
|
-
|
98
|
-
def shard_file_path
|
99
|
-
path = file_path(shard.username, shard.name, shard.version, '*shard.rb')
|
100
|
-
Dir[ path ].first
|
101
|
-
end
|
102
|
-
|
103
|
-
def shard_test_paths
|
104
|
-
test_path = file_path(shard.username, shard.name, shard.version, '*_test.rb')
|
105
|
-
test_files = Dir[ test_path ]
|
106
|
-
|
107
|
-
spec_path = file_path(shard.username, shard.name, shard.version, '*_spec.rb')
|
108
|
-
spec_files = Dir[ spec_path ]
|
109
|
-
|
110
|
-
test_files + spec_files
|
67
|
+
Shard::Saver.save ref, lazy: true
|
111
68
|
end
|
112
69
|
|
113
70
|
end
|
data/lib/shard/ref.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Shard
|
2
|
+
|
3
|
+
class Ref < Struct.new(:user, :name, :file, :version)
|
4
|
+
|
5
|
+
################
|
6
|
+
# #
|
7
|
+
# Declarations #
|
8
|
+
# #
|
9
|
+
################
|
10
|
+
|
11
|
+
PATTERN = %r{([a-zA-Z0-9_-]+)/(\w+)} # (?::(\w+))?
|
12
|
+
|
13
|
+
#################
|
14
|
+
# #
|
15
|
+
# Class Methods #
|
16
|
+
# #
|
17
|
+
#################
|
18
|
+
|
19
|
+
def self.parse(shard_line)
|
20
|
+
if matcher = shard_line.match(PATTERN)
|
21
|
+
user = matcher[1]
|
22
|
+
name = matcher[2]
|
23
|
+
file = nil
|
24
|
+
version = 'HEAD'
|
25
|
+
|
26
|
+
new(user, name, file, version)
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.valid?(shard_line)
|
33
|
+
shard_line =~ PATTERN
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/shard/saver.rb
CHANGED
@@ -10,7 +10,9 @@ class Shard
|
|
10
10
|
|
11
11
|
include ShardDirectory
|
12
12
|
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :ref, :gist, :full_gist, :options
|
14
|
+
|
15
|
+
SHA_LENGTH = 8
|
14
16
|
|
15
17
|
###############
|
16
18
|
# #
|
@@ -18,8 +20,8 @@ class Shard
|
|
18
20
|
# #
|
19
21
|
###############
|
20
22
|
|
21
|
-
def initialize(
|
22
|
-
@
|
23
|
+
def initialize(shard_line_or_ref, options = {})
|
24
|
+
@ref = Shard::Ref(shard_line_or_ref)
|
23
25
|
@options = options
|
24
26
|
end
|
25
27
|
|
@@ -29,8 +31,8 @@ class Shard
|
|
29
31
|
# #
|
30
32
|
#################
|
31
33
|
|
32
|
-
def self.save(
|
33
|
-
new(
|
34
|
+
def self.save(shard_line, options = {})
|
35
|
+
new(shard_line, options).save!
|
34
36
|
end
|
35
37
|
|
36
38
|
####################
|
@@ -40,7 +42,9 @@ class Shard
|
|
40
42
|
####################
|
41
43
|
|
42
44
|
def save!
|
43
|
-
|
45
|
+
return if shard_dir_exists?(ref) && options[:lazy]
|
46
|
+
|
47
|
+
create_shard_dir(ref)
|
44
48
|
fetch_shard_contents
|
45
49
|
|
46
50
|
gist.all_files.each do |file|
|
@@ -48,16 +52,16 @@ class Shard
|
|
48
52
|
end
|
49
53
|
|
50
54
|
if options[:verbose]
|
51
|
-
puts "VERSION #{ version
|
55
|
+
puts "VERSION #{ version }..."
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
59
|
private
|
56
60
|
|
57
61
|
def fetch_shard_contents
|
58
|
-
lister = Shard::Lister.new(
|
59
|
-
@gist = lister.shards[
|
60
|
-
@full_gist =
|
62
|
+
lister = Shard::Lister.new(ref.user)
|
63
|
+
@gist = lister.shards[ref.name]
|
64
|
+
@full_gist = Shard.api.gist gist.id
|
61
65
|
end
|
62
66
|
|
63
67
|
def file_contents(filename)
|
@@ -65,7 +69,7 @@ class Shard
|
|
65
69
|
end
|
66
70
|
|
67
71
|
def write_file(file)
|
68
|
-
path = file_path(
|
72
|
+
path = file_path(ref, file.filename)
|
69
73
|
contents = file_contents(file.filename)
|
70
74
|
|
71
75
|
if options[:verbose]
|
@@ -75,7 +79,7 @@ class Shard
|
|
75
79
|
File.write path, contents
|
76
80
|
end
|
77
81
|
|
78
|
-
def version(length)
|
82
|
+
def version(length = SHA_LENGTH)
|
79
83
|
full_version = full_gist.history.first.version
|
80
84
|
full_version[0...length]
|
81
85
|
end
|
@@ -8,36 +8,40 @@ class Shard
|
|
8
8
|
# #
|
9
9
|
##################
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
Dir.mkdir(path)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def create_shard_dir(username, shard, version)
|
18
|
-
dir = directory(username, shard, version)
|
11
|
+
def create_shard_dir(ref)
|
12
|
+
dir = directory(ref)
|
19
13
|
|
20
|
-
unless shard_dir_exists?(
|
14
|
+
unless shard_dir_exists?(ref)
|
21
15
|
FileUtils.mkpath(dir)
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
25
|
-
def shard_dir_exists?(
|
26
|
-
|
27
|
-
|
28
|
-
Dir.exists?(dir)
|
19
|
+
def shard_dir_exists?(ref)
|
20
|
+
Dir.exists? directory(ref)
|
29
21
|
end
|
30
22
|
|
31
|
-
def directory(
|
32
|
-
File.join(
|
23
|
+
def directory(ref)
|
24
|
+
File.join(root_path, ref.user, ref.name, ref.version)
|
33
25
|
end
|
34
26
|
|
35
|
-
def
|
27
|
+
def root_path
|
36
28
|
File.join(Dir.home, '.shard')
|
37
29
|
end
|
38
30
|
|
39
|
-
def file_path(
|
40
|
-
File.join( directory(
|
31
|
+
def file_path(ref, filename, options = {})
|
32
|
+
File.join( directory(ref), filename )
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_file_path(ref, filename, options = {})
|
36
|
+
find_file_paths(ref, filename).first
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_file_paths(ref, *filenames)
|
40
|
+
full_names = filenames.map do |filename|
|
41
|
+
File.join( directory(ref), filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
Dir[ *full_names ]
|
41
45
|
end
|
42
46
|
|
43
47
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,27 +12,60 @@ cert_chain: []
|
|
12
12
|
date: 2013-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: octokit
|
16
|
+
requirement: &70161726787500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - =
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.25.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70161726787500
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: netrc
|
27
|
+
requirement: &70161726786820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 0.7.7
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70161726786820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: thor
|
38
|
+
requirement: &70161726786340 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.18.1
|
33
44
|
type: :runtime
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70161726786340
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70161726785960 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70161726785960
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &70161726785480 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70161726785480
|
36
69
|
description: ! 'Shard is a light-weight code loading-and-running-and-sharing tool,
|
37
70
|
built on top of http://gist.github.com.
|
38
71
|
|
@@ -48,14 +81,19 @@ extensions: []
|
|
48
81
|
extra_rdoc_files: []
|
49
82
|
files:
|
50
83
|
- lib/shard.rb
|
84
|
+
- lib/shard/cli/commands.rb
|
85
|
+
- lib/shard/cli/config.rb
|
86
|
+
- lib/shard/cli/fork.rb
|
87
|
+
- lib/shard/cli/list.rb
|
51
88
|
- lib/shard/cli.rb
|
89
|
+
- lib/shard/credentials.rb
|
52
90
|
- lib/shard/gist.rb
|
53
91
|
- lib/shard/kernel.rb
|
54
92
|
- lib/shard/lister.rb
|
55
93
|
- lib/shard/loader.rb
|
94
|
+
- lib/shard/ref.rb
|
56
95
|
- lib/shard/saver.rb
|
57
96
|
- lib/shard/shard_directory.rb
|
58
|
-
- lib/shard/shard_record.rb
|
59
97
|
- bin/shard
|
60
98
|
homepage: https://github.com/mark/shard
|
61
99
|
licenses:
|
data/lib/shard/shard_record.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
class Shard::ShardRecord
|
2
|
-
|
3
|
-
################
|
4
|
-
# #
|
5
|
-
# Declarations #
|
6
|
-
# #
|
7
|
-
################
|
8
|
-
|
9
|
-
attr_reader :username, :name, :version
|
10
|
-
|
11
|
-
###############
|
12
|
-
# #
|
13
|
-
# Constructor #
|
14
|
-
# #
|
15
|
-
###############
|
16
|
-
|
17
|
-
def initialize(username, name, version = "HEAD")
|
18
|
-
@username = username
|
19
|
-
@name = name
|
20
|
-
@version = version
|
21
|
-
end
|
22
|
-
|
23
|
-
####################
|
24
|
-
# #
|
25
|
-
# Instance Methods #
|
26
|
-
# #
|
27
|
-
####################
|
28
|
-
|
29
|
-
end
|