social_snippet 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +11 -4
- data/README.md +6 -6
- data/Rakefile +19 -1
- data/lib/social_snippet.rb +11 -0
- data/lib/social_snippet/api/install_repository_api.rb +23 -82
- data/lib/social_snippet/api/manifest_api.rb +3 -3
- data/lib/social_snippet/api/update_repository_api.rb +34 -35
- data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +7 -7
- data/lib/social_snippet/config.rb +18 -8
- data/lib/social_snippet/core.rb +13 -0
- data/lib/social_snippet/document.rb +2 -0
- data/lib/social_snippet/document_backend.rb +2 -0
- data/lib/social_snippet/document_backend/yaml_document.rb +252 -0
- data/lib/social_snippet/document_backend/yaml_document/query.rb +45 -0
- data/lib/social_snippet/repository.rb +2 -2
- data/lib/social_snippet/repository/driver_factory.rb +42 -0
- data/lib/social_snippet/repository/drivers.rb +3 -2
- data/lib/social_snippet/repository/drivers/driver_base.rb +100 -0
- data/lib/social_snippet/repository/drivers/entry.rb +11 -0
- data/lib/social_snippet/repository/drivers/git_driver.rb +100 -0
- data/lib/social_snippet/repository/models.rb +15 -0
- data/lib/social_snippet/repository/models/package.rb +97 -0
- data/lib/social_snippet/repository/models/repository.rb +94 -0
- data/lib/social_snippet/repository/repository_manager.rb +79 -67
- data/lib/social_snippet/resolvers/base_resolver.rb +13 -17
- data/lib/social_snippet/rspec/test_document.rb +305 -0
- data/lib/social_snippet/rspec/test_driver.rb +76 -0
- data/lib/social_snippet/rspec/test_storage.rb +459 -0
- data/lib/social_snippet/storage.rb +1 -0
- data/lib/social_snippet/storage_backend.rb +3 -0
- data/lib/social_snippet/storage_backend/file_system_storage.rb +71 -0
- data/lib/social_snippet/storage_backend/storage_base.rb +35 -0
- data/lib/social_snippet/version.rb +8 -3
- data/spec/helpers/codeclimate_helper.rb +1 -1
- data/spec/helpers/fakefs_helper.rb +10 -0
- data/spec/helpers/social_snippet_helper.rb +117 -0
- data/spec/lib/api/insert_snippet_spec.rb +95 -2
- data/spec/lib/api/update_repository_spec.rb +196 -0
- data/spec/lib/command_line/sspm_install_spec.rb +169 -180
- data/spec/lib/command_line/sspm_update_spec.rb +56 -0
- data/spec/lib/config_spec.rb +6 -8
- data/spec/lib/core_spec.rb +21 -38
- data/spec/lib/file_system_storage_spec.rb +170 -0
- data/spec/lib/insert_resolver_spec.rb +15 -2
- data/spec/lib/registry_client_spec.rb +6 -9
- data/spec/lib/repository/driver_base_spec.rb +89 -0
- data/spec/lib/repository/git_driver_spec.rb +10 -0
- data/spec/lib/repository/package_spec.rb +172 -0
- data/spec/lib/repository/repository_factory_spec.rb +67 -22
- data/spec/lib/repository/repository_manager_spec.rb +71 -114
- data/spec/lib/repository/repository_spec.rb +191 -0
- data/spec/lib/yaml_document_spec.rb +14 -0
- data/spec/spec_helper.rb +8 -93
- data/test/config_test.rb +6 -7
- data/test/driver_base_test.rb +201 -0
- data/test/git_driver_test.rb +51 -0
- data/test/insert_snippet_test.rb +256 -349
- data/test/repository_manager_test.rb +7 -16
- data/test/yaml_document_test.rb +97 -0
- metadata +44 -16
- data/lib/social_snippet/repository/drivers/base_repository.rb +0 -189
- data/lib/social_snippet/repository/drivers/git_repository.rb +0 -74
- data/lib/social_snippet/repository/repository_factory.rb +0 -59
- data/lib/social_snippet/repository/repository_installer.rb +0 -85
- data/spec/lib/repository/base_repository_spec.rb +0 -104
- data/spec/lib/repository/git_repository_spec.rb +0 -83
- data/spec/lib/repository/repository_installer_spec.rb +0 -63
- data/test/base_repository_test.rb +0 -375
- data/test/git_repository_test.rb +0 -114
@@ -1,74 +0,0 @@
|
|
1
|
-
module SocialSnippet::Repository::Drivers
|
2
|
-
|
3
|
-
class GitRepository < BaseRepository
|
4
|
-
|
5
|
-
attr_reader :rugged_repo
|
6
|
-
|
7
|
-
def initialize(repo_path, new_ref = nil)
|
8
|
-
@rugged_repo = ::Rugged::Repository.new(repo_path)
|
9
|
-
super(repo_path)
|
10
|
-
end
|
11
|
-
|
12
|
-
def current_ref
|
13
|
-
rugged_repo.head.name.gsub /^refs\/heads\//, ""
|
14
|
-
end
|
15
|
-
|
16
|
-
def update
|
17
|
-
# TODO: write tests
|
18
|
-
fetch_status = rugged_repo.fetch("origin")
|
19
|
-
fetch_status[:received_bytes]
|
20
|
-
end
|
21
|
-
|
22
|
-
def commit_id
|
23
|
-
rugged_repo.head.target_id
|
24
|
-
end
|
25
|
-
|
26
|
-
def checkout(ref_name)
|
27
|
-
rugged_repo.checkout ref_name, :strategy => [:force]
|
28
|
-
end
|
29
|
-
|
30
|
-
def refs
|
31
|
-
refs = []
|
32
|
-
refs.concat remote_refs
|
33
|
-
refs.concat tags
|
34
|
-
return refs
|
35
|
-
end
|
36
|
-
|
37
|
-
def remote_refs
|
38
|
-
rugged_repo.references
|
39
|
-
.select {|ref| /^refs\/remotes\/origin\// === ref.name }
|
40
|
-
.map {|ref| /^refs\/remotes\/origin\/(.*)/.match(ref.name)[1] }
|
41
|
-
end
|
42
|
-
|
43
|
-
def tags
|
44
|
-
rugged_repo.references
|
45
|
-
.select {|ref| /^refs\/tags\// === ref.name }
|
46
|
-
.map {|ref| /^refs\/tags\/(.*)/.match(ref.name)[1] }
|
47
|
-
end
|
48
|
-
|
49
|
-
class << self
|
50
|
-
|
51
|
-
# @return path
|
52
|
-
def download(uri, dest_path = nil)
|
53
|
-
if dest_path.nil?
|
54
|
-
dest_path = Dir.mktmpdir
|
55
|
-
end
|
56
|
-
|
57
|
-
# git clone
|
58
|
-
cloned_repo = ::Rugged::Repository.clone_at uri.to_s, dest_path
|
59
|
-
cloned_repo_files = cloned_repo.head.target.tree.map {|item| item[:name] }
|
60
|
-
|
61
|
-
# check snippet.json
|
62
|
-
unless cloned_repo_files.include?("snippet.json")
|
63
|
-
raise "ERROR: Not found snippet.json in the repository"
|
64
|
-
end
|
65
|
-
|
66
|
-
cloned_repo.close
|
67
|
-
dest_path
|
68
|
-
end
|
69
|
-
|
70
|
-
end # class << self
|
71
|
-
|
72
|
-
end # GitRepository
|
73
|
-
|
74
|
-
end # SocialSnippet
|
@@ -1,59 +0,0 @@
|
|
1
|
-
module SocialSnippet::Repository::RepositoryFactory
|
2
|
-
|
3
|
-
class << self
|
4
|
-
|
5
|
-
def clone(repo_url)
|
6
|
-
uri = URI.parse repo_url
|
7
|
-
if is_git_repo(uri)
|
8
|
-
path = ::SocialSnippet::Repository::Drivers::GitRepository.download uri
|
9
|
-
repo = create_git_repo(path)
|
10
|
-
repo.set_url repo_url
|
11
|
-
repo.load_snippet_json
|
12
|
-
return repo
|
13
|
-
else
|
14
|
-
raise "unknown repository type"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def clone_local(repo_path)
|
19
|
-
if has_git_dir?(repo_path)
|
20
|
-
cloned_path = ::SocialSnippet::Repository::Drivers::GitRepository.download repo_path
|
21
|
-
repo = create_git_repo(cloned_path)
|
22
|
-
repo.set_url repo_path
|
23
|
-
repo.load_snippet_json
|
24
|
-
return repo
|
25
|
-
else
|
26
|
-
raise "unknown local repository type"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Create suitable Repository class instance from path
|
31
|
-
#
|
32
|
-
# @param path [String] The path of repository
|
33
|
-
def create(path, ref = nil, options = {})
|
34
|
-
if has_git_dir?(path)
|
35
|
-
repo = create_git_repo(path, ref)
|
36
|
-
repo.load_snippet_json
|
37
|
-
return repo
|
38
|
-
end
|
39
|
-
|
40
|
-
return nil
|
41
|
-
end
|
42
|
-
|
43
|
-
def create_git_repo(path, ref = nil)
|
44
|
-
::SocialSnippet::Repository::Drivers::GitRepository.new(path, ref)
|
45
|
-
end
|
46
|
-
|
47
|
-
def has_git_dir?(dir_path)
|
48
|
-
Dir.exists?("#{dir_path}/.git")
|
49
|
-
end
|
50
|
-
|
51
|
-
def is_git_repo(uri)
|
52
|
-
return true if uri.scheme === "git"
|
53
|
-
return true if uri.host === "github.com"
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
|
57
|
-
end # class << self
|
58
|
-
|
59
|
-
end # RepositoryFactory
|
@@ -1,85 +0,0 @@
|
|
1
|
-
module SocialSnippet::Repository
|
2
|
-
|
3
|
-
class RepositoryInstaller
|
4
|
-
|
5
|
-
attr_reader :core
|
6
|
-
attr_reader :data
|
7
|
-
|
8
|
-
def initialize(new_core)
|
9
|
-
@core = new_core
|
10
|
-
init_data
|
11
|
-
end
|
12
|
-
|
13
|
-
def path
|
14
|
-
core.config.install_path
|
15
|
-
end
|
16
|
-
|
17
|
-
def data_file
|
18
|
-
core.config.installed_repos_file
|
19
|
-
end
|
20
|
-
|
21
|
-
def init_data
|
22
|
-
::FileUtils.touch data_file
|
23
|
-
load
|
24
|
-
reset unless data
|
25
|
-
end
|
26
|
-
|
27
|
-
def reset
|
28
|
-
@data = {}
|
29
|
-
save
|
30
|
-
end
|
31
|
-
|
32
|
-
def load
|
33
|
-
@data = ::YAML.load_file(data_file)
|
34
|
-
end
|
35
|
-
|
36
|
-
def save
|
37
|
-
::File.write data_file, data.to_yaml
|
38
|
-
end
|
39
|
-
|
40
|
-
def add(repo_name, repo_ref)
|
41
|
-
data[repo_name] ||= Set.new
|
42
|
-
data[repo_name].add repo_ref
|
43
|
-
save
|
44
|
-
end
|
45
|
-
|
46
|
-
def remove(repo_name, repo_ref)
|
47
|
-
data[repo_name] ||= Set.new
|
48
|
-
data[repo_name].delete repo_ref
|
49
|
-
save
|
50
|
-
end
|
51
|
-
|
52
|
-
def exists?(repo_name, repo_ref = nil)
|
53
|
-
data[repo_name] ||= Set.new
|
54
|
-
if repo_ref.nil?
|
55
|
-
data[repo_name].empty? === false
|
56
|
-
else
|
57
|
-
data[repo_name].include? repo_ref
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def copy_repository(repo, options = {})
|
62
|
-
core.logger.debug "repository_installer: repo.path = #{repo.path}"
|
63
|
-
::FileUtils.cp_r repo.path, repo_path(repo.name)
|
64
|
-
end
|
65
|
-
|
66
|
-
def fetch(repo_name, options)
|
67
|
-
repo = ::SocialSnippet::Repository::RepositoryFactory.create(repo_path(repo_name), options)
|
68
|
-
repo.update
|
69
|
-
end
|
70
|
-
|
71
|
-
def repo_path(name)
|
72
|
-
::File.join(path, name)
|
73
|
-
end
|
74
|
-
|
75
|
-
def each(&block)
|
76
|
-
data
|
77
|
-
.select {|repo_name, repo_refs| not repo_refs.empty? }
|
78
|
-
.keys
|
79
|
-
.each {|repo_name| block.call repo_name }
|
80
|
-
end
|
81
|
-
|
82
|
-
end # RepositoryInstaller
|
83
|
-
|
84
|
-
end # SocialSnippet
|
85
|
-
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module SocialSnippet::Repository::Drivers
|
4
|
-
|
5
|
-
describe BaseRepository do
|
6
|
-
|
7
|
-
describe "#to_snippet_json" do
|
8
|
-
|
9
|
-
let(:instance) { BaseRepository.new "/path/to/repo" }
|
10
|
-
|
11
|
-
before do
|
12
|
-
FileUtils.mkdir_p "/path/to/repo"
|
13
|
-
FileUtils.mkdir_p "/path/to/repo/my-src"
|
14
|
-
FileUtils.touch "/path/to/repo/snippet.json"
|
15
|
-
|
16
|
-
File.write "/path/to/repo/snippet.json", [
|
17
|
-
'{',
|
18
|
-
' "name": "my-name",',
|
19
|
-
' "desc": "my-desc",',
|
20
|
-
' "main": "my-src"',
|
21
|
-
'}',
|
22
|
-
].join($/)
|
23
|
-
end # prepare /path/to/repo
|
24
|
-
|
25
|
-
context "load snippet.json" do
|
26
|
-
|
27
|
-
before { instance.load_snippet_json }
|
28
|
-
let(:result) { JSON.parse(instance.to_snippet_json) }
|
29
|
-
|
30
|
-
it { expect(result["name"]).to eq "my-name" }
|
31
|
-
it { expect(result["desc"]).to eq "my-desc" }
|
32
|
-
it { expect(result["main"]).to eq "my-src" }
|
33
|
-
|
34
|
-
end # load snippet.json
|
35
|
-
|
36
|
-
end # to_snippet_json
|
37
|
-
|
38
|
-
describe "#glob" do
|
39
|
-
|
40
|
-
let(:instance) { BaseRepository.new "/path/to/my-repo" }
|
41
|
-
|
42
|
-
before do
|
43
|
-
FileUtils.mkdir_p "/path/to/my-repo/"
|
44
|
-
FileUtils.mkdir_p "/path/to/my-repo/.git/"
|
45
|
-
FileUtils.mkdir_p "/path/to/my-repo/src/"
|
46
|
-
FileUtils.mkdir_p "/path/to/my-repo/src/sub/"
|
47
|
-
FileUtils.touch "/path/to/my-repo/snippet.json"
|
48
|
-
FileUtils.touch "/path/to/my-repo/src/file.cpp"
|
49
|
-
FileUtils.touch "/path/to/my-repo/src/sub/sub_file_1.cpp"
|
50
|
-
FileUtils.touch "/path/to/my-repo/src/sub/sub_file_2.cpp"
|
51
|
-
FileUtils.touch "/path/to/my-repo/src/sub/sub_file_3.cpp"
|
52
|
-
|
53
|
-
File.write "/path/to/my-repo/snippet.json", [
|
54
|
-
'{',
|
55
|
-
' "name": "my-name",',
|
56
|
-
' "desc": "my-desc",',
|
57
|
-
' "main": "src"',
|
58
|
-
'}',
|
59
|
-
].join($/)
|
60
|
-
end # prepare install_path
|
61
|
-
|
62
|
-
context "load snippet.json" do
|
63
|
-
|
64
|
-
before { instance.load_snippet_json }
|
65
|
-
|
66
|
-
context "glob = file.cpp" do
|
67
|
-
subject { instance.glob("file.cpp").map {|file_path| Pathname(file_path).basename.to_s } }
|
68
|
-
it { should include "file.cpp" }
|
69
|
-
it { should_not include "sub_file_1.cpp" }
|
70
|
-
it { should_not include "sub_file_2.cpp" }
|
71
|
-
it { should_not include "sub_file_3.cpp" }
|
72
|
-
end
|
73
|
-
|
74
|
-
context "glob = file*" do
|
75
|
-
subject { instance.glob("file*").map {|file_path| Pathname(file_path).basename.to_s } }
|
76
|
-
it { should include "file.cpp" }
|
77
|
-
it { should_not include "sub_file_1.cpp" }
|
78
|
-
it { should_not include "sub_file_2.cpp" }
|
79
|
-
it { should_not include "sub_file_3.cpp" }
|
80
|
-
end
|
81
|
-
|
82
|
-
context "glob = sub/*" do
|
83
|
-
subject { instance.glob("sub/*").map {|file_path| Pathname(file_path).basename.to_s } }
|
84
|
-
it { should_not include "file.cpp" }
|
85
|
-
it { should include "sub_file_1.cpp" }
|
86
|
-
it { should include "sub_file_2.cpp" }
|
87
|
-
it { should include "sub_file_3.cpp" }
|
88
|
-
end
|
89
|
-
|
90
|
-
context "glob = sub/sub_file_2.*" do
|
91
|
-
subject { instance.glob("sub/sub_file_2.*").map {|file_path| Pathname(file_path).basename.to_s } }
|
92
|
-
it { should_not include "file.cpp" }
|
93
|
-
it { should_not include "sub_file_1.cpp" }
|
94
|
-
it { should include "sub_file_2.cpp" }
|
95
|
-
it { should_not include "sub_file_3.cpp" }
|
96
|
-
end
|
97
|
-
|
98
|
-
end # load snippet.json
|
99
|
-
|
100
|
-
end # glob
|
101
|
-
|
102
|
-
end # BaseRepository
|
103
|
-
|
104
|
-
end # SocialSnippet::Repository::Drivers
|
@@ -1,83 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
module SocialSnippet::Repository::Drivers
|
4
|
-
|
5
|
-
describe GitRepository, :without_fakefs => true do
|
6
|
-
|
7
|
-
before { disable_fakefs }
|
8
|
-
|
9
|
-
context "github repo" do
|
10
|
-
|
11
|
-
context "clone social-snippet/example-repo" do
|
12
|
-
|
13
|
-
subject(:repo) { ::SocialSnippet::Repository::RepositoryFactory.clone("git://github.com/social-snippet/example-repo.git") }
|
14
|
-
|
15
|
-
context "load snippet.json" do
|
16
|
-
before { repo.load_snippet_json }
|
17
|
-
it { expect(repo.name).to eq "example-repo" }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#refs" do
|
21
|
-
subject { repo.refs }
|
22
|
-
it { should include "master" }
|
23
|
-
it { should include "1.0.0" }
|
24
|
-
it { should include "1.0.1" }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#versions" do
|
28
|
-
subject { repo.versions }
|
29
|
-
it { should_not include "master" }
|
30
|
-
it { should include "1.0.0" }
|
31
|
-
it { should include "1.0.1" }
|
32
|
-
end
|
33
|
-
|
34
|
-
context "checkout 1.0.0" do
|
35
|
-
|
36
|
-
before do
|
37
|
-
repo.checkout("1.0.0")
|
38
|
-
repo.load_snippet_json
|
39
|
-
end
|
40
|
-
|
41
|
-
it { expect(repo.name).to eq "example-repo" }
|
42
|
-
|
43
|
-
describe "#commit_id" do
|
44
|
-
subject { repo.commit_id }
|
45
|
-
it { should eq "efa58ecae07cf3d063ae75fa97fce164c56d205a" }
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#short_commit_id" do
|
49
|
-
subject { repo.short_commit_id }
|
50
|
-
it { should eq "efa58eca" }
|
51
|
-
end
|
52
|
-
|
53
|
-
end # checkout 1.0.0
|
54
|
-
|
55
|
-
context "checkout 1.0.x (latest)" do
|
56
|
-
|
57
|
-
before do
|
58
|
-
repo.checkout(repo.latest_version("1.0"))
|
59
|
-
repo.load_snippet_json
|
60
|
-
end
|
61
|
-
|
62
|
-
it { expect(repo.name).to eq "example-repo" }
|
63
|
-
|
64
|
-
describe "#commit_id" do
|
65
|
-
subject { repo.commit_id }
|
66
|
-
it { should eq "38ebf733622174e24d76d28ab264c52b4fd7bda9" }
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#short_commit_id" do
|
70
|
-
subject { repo.short_commit_id }
|
71
|
-
it { should eq "38ebf733" }
|
72
|
-
end
|
73
|
-
|
74
|
-
end # checkout 1.0.x
|
75
|
-
|
76
|
-
end # clone social_snippet/example-repo
|
77
|
-
|
78
|
-
end # github repo
|
79
|
-
|
80
|
-
end # GitRepository
|
81
|
-
|
82
|
-
end # SocialSnippet::Repository::Drivers
|
83
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe ::SocialSnippet::Repository::RepositoryInstaller do
|
4
|
-
|
5
|
-
let(:config) { ::SocialSnippet::Config.new(social_snippet) }
|
6
|
-
|
7
|
-
let(:social_snippet) do
|
8
|
-
class Fake; end
|
9
|
-
Fake.new
|
10
|
-
end
|
11
|
-
|
12
|
-
before do
|
13
|
-
allow(social_snippet).to receive(:config).and_return config
|
14
|
-
end
|
15
|
-
|
16
|
-
let(:installer) { ::SocialSnippet::Repository::RepositoryInstaller.new social_snippet }
|
17
|
-
|
18
|
-
|
19
|
-
describe "#each()" do
|
20
|
-
|
21
|
-
context "add four repos" do
|
22
|
-
|
23
|
-
before do
|
24
|
-
installer.add "my-repo-1", "0.0.1"
|
25
|
-
installer.add "my-repo-2", "0.0.1"
|
26
|
-
installer.add "my-repo-2", "0.0.2"
|
27
|
-
installer.add "my-repo-3", "0.0.1"
|
28
|
-
end # prepare for repos
|
29
|
-
|
30
|
-
context "call each()" do
|
31
|
-
it { expect {|b| installer.each &b }.to yield_successive_args("my-repo-1", "my-repo-2", "my-repo-3") }
|
32
|
-
end
|
33
|
-
|
34
|
-
end # add four repos
|
35
|
-
|
36
|
-
end # each
|
37
|
-
|
38
|
-
|
39
|
-
context "add my-repo#0.0.1" do
|
40
|
-
|
41
|
-
before { installer.add "my-repo", "0.0.1" }
|
42
|
-
|
43
|
-
context "installed my-repo#0.0.1" do
|
44
|
-
subject { installer.exists? "my-repo", "0.0.1" }
|
45
|
-
it { should be_truthy }
|
46
|
-
|
47
|
-
context "remove my-repo#0.0.1" do
|
48
|
-
before { installer.remove "my-repo", "0.0.1" }
|
49
|
-
|
50
|
-
context "not installed my-repo#0.0.1" do
|
51
|
-
|
52
|
-
subject { installer.exists? "my-repo", "0.0.1" }
|
53
|
-
it { should be_falsey }
|
54
|
-
|
55
|
-
end # not installed my-repo#0.0.1
|
56
|
-
|
57
|
-
end # remove my-repo#0.0.1
|
58
|
-
|
59
|
-
end # installed my-repo#0.0.1
|
60
|
-
|
61
|
-
end # add my-repo#0.0.1
|
62
|
-
|
63
|
-
end # ::SocialSnippet::Repository::RepositoryInstaller
|