social_snippet 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/social_snippet/repository/models/package.rb +4 -0
- data/lib/social_snippet/repository/repository_manager.rb +24 -8
- data/lib/social_snippet/rspec/test_storage.rb +57 -0
- data/lib/social_snippet/version.rb +1 -1
- data/social_snippet.gemspec +1 -1
- data/spec/lib/api/completion_api_spec.rb +128 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjJkOWViMTBkNjE5NDJiMTEzN2I1MTkwMjRiOTkxMjY0NzdiYzY5ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWM0MGM0ZjYxOTc1OTI5MmU4MmI0MDkyM2RmZDU2MTMyM2FiOWU5Mw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2NlYmU0MDc0ZTQ0NWI4NTU2YjVlYzYzYzkwZWYyM2ZkMGQ0NTY3NmZkZTY2
|
10
|
+
MDdlZjgzZDg3NWM0YWZlZDVkOGM0YWU2YWI1YTc2MTYxZGIyZTNkY2MyNzhh
|
11
|
+
NjM5MDEzOWEzNWEwODAzMDJhZjIzYTdkY2M3NTZjMTc5Y2IwOGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTc5ODRjYWUzM2Y5NjJmOGY0NDRhYjZmNDRkYzA4ODg2OGYzN2M3MmI1N2Zh
|
14
|
+
ZmM3MGNhNmE0ZmVmYjE1ZjM4MTc2ZWRmOGQ0Y2RmODBkYTYwMjcwNDc2ZGU5
|
15
|
+
NDI2ZDlhYWIyZTg5OTRiNWZhY2VjYThhNTljZjdjZDBjMTdkNGY=
|
@@ -38,6 +38,10 @@ module SocialSnippet::Repository::Models
|
|
38
38
|
core.storage.write file_path, data
|
39
39
|
end
|
40
40
|
|
41
|
+
def directory?(path)
|
42
|
+
core.storage.directory? real_path(normalize_path path)
|
43
|
+
end
|
44
|
+
|
41
45
|
def add_dependency(new_name, new_ref)
|
42
46
|
add_to_set :dependencies_array => {
|
43
47
|
:name => new_name,
|
@@ -71,22 +71,38 @@ module SocialSnippet::Repository
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def all_repositories
|
75
|
+
Models::Repository.all.map {|repo| repo.name }
|
76
|
+
end
|
77
|
+
|
74
78
|
def complete_repo_name(keyword)
|
75
79
|
repo_name = get_repo_name_prefix(keyword)
|
76
|
-
|
80
|
+
if repo_name.empty?
|
81
|
+
all_repositories
|
82
|
+
else
|
83
|
+
find_repositories_start_with(repo_name)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def package_glob_path(package, path)
|
88
|
+
if package.snippet_json["main"].nil?
|
89
|
+
"#{path}*"
|
90
|
+
else
|
91
|
+
"#{package.snippet_json["main"]}/#{path}*"
|
92
|
+
end
|
77
93
|
end
|
78
94
|
|
79
95
|
def complete_file_name(keyword)
|
80
96
|
repo_name = get_repo_name(keyword)
|
81
97
|
package = find_package(repo_name)
|
82
98
|
file_path = keyword_filepath(keyword)
|
83
|
-
glob_path =
|
99
|
+
glob_path = package_glob_path(package, file_path)
|
84
100
|
|
85
|
-
package.glob(glob_path).map do |
|
86
|
-
if
|
87
|
-
Pathname(
|
101
|
+
package.glob(glob_path).map do |path|
|
102
|
+
if package.directory?(path)
|
103
|
+
::Pathname.new(path).basename.to_s + "/"
|
88
104
|
else
|
89
|
-
Pathname(
|
105
|
+
::Pathname.new(path).basename.to_s + ">"
|
90
106
|
end
|
91
107
|
end
|
92
108
|
end
|
@@ -102,11 +118,11 @@ module SocialSnippet::Repository
|
|
102
118
|
end
|
103
119
|
|
104
120
|
def get_repo_name(keyword)
|
105
|
-
/^[^@]*@[^<]+<([^:#>]*
|
121
|
+
/^[^@]*@[^<]+<([^:#>]*)/.match(keyword)[1]
|
106
122
|
end
|
107
123
|
|
108
124
|
def get_repo_name_prefix(keyword)
|
109
|
-
/^[^@]*@[^<]+<([^:#>]*
|
125
|
+
/^[^@]*@[^<]+<([^:#>]*)$/.match(keyword)[1]
|
110
126
|
end
|
111
127
|
|
112
128
|
def keyword_filepath(keyword)
|
@@ -6,6 +6,63 @@ RSpec.configure do
|
|
6
6
|
|
7
7
|
let(:storage) { ::SocialSnippet::Storage.new }
|
8
8
|
|
9
|
+
describe "#directory?" do
|
10
|
+
|
11
|
+
context "mkdir dir" do
|
12
|
+
|
13
|
+
before { storage.mkdir_p "dir" }
|
14
|
+
|
15
|
+
context "directory? dir" do
|
16
|
+
subject { storage.directory? "dir" }
|
17
|
+
it { should be_truthy }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "directory? dir/" do
|
21
|
+
subject { storage.directory? "dir/" }
|
22
|
+
it { should be_truthy }
|
23
|
+
end
|
24
|
+
|
25
|
+
context "file? dir" do
|
26
|
+
subject { storage.file? "dir" }
|
27
|
+
it { should be_falsey }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "file? dir/" do
|
31
|
+
subject { storage.file? "dir/" }
|
32
|
+
it { should be_falsey }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "write dir/file.txt" do
|
36
|
+
before { storage.write "dir/file.txt", "" }
|
37
|
+
context "directory? dir" do
|
38
|
+
subject { storage.directory? "dir" }
|
39
|
+
it { should be_truthy }
|
40
|
+
end
|
41
|
+
context "directory? dir/" do
|
42
|
+
subject { storage.directory? "dir/" }
|
43
|
+
it { should be_truthy }
|
44
|
+
end
|
45
|
+
context "file? dir" do
|
46
|
+
subject { storage.file? "dir" }
|
47
|
+
it { should be_falsey }
|
48
|
+
end
|
49
|
+
context "file? dir/" do
|
50
|
+
subject { storage.file? "dir/" }
|
51
|
+
it { should be_falsey }
|
52
|
+
end
|
53
|
+
context "file? dir/file.txt" do
|
54
|
+
subject { storage.file? "dir/file.txt" }
|
55
|
+
it { should be_truthy }
|
56
|
+
end
|
57
|
+
context "directory? dir/file.txt" do
|
58
|
+
subject { storage.directory? "dir/file.txt" }
|
59
|
+
it { should be_falsey }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end #directory?
|
65
|
+
|
9
66
|
describe "no entry" do
|
10
67
|
|
11
68
|
context "read not_found.txt" do
|
data/social_snippet.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.required_ruby_version = ">= 1.9.3"
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "version_sorter", "~> 2.0.0"
|
23
|
-
spec.add_runtime_dependency "rest-client", "~> 1.
|
23
|
+
spec.add_runtime_dependency "rest-client", "~> 1.8.0"
|
24
24
|
spec.add_runtime_dependency "highline", "~> 1.7.0"
|
25
25
|
spec.add_runtime_dependency "wisper", "~> 1.6.0"
|
26
26
|
spec.add_runtime_dependency "social_snippet-supports-git", "~> 0.1.0"
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ::SocialSnippet::Api::CompletionApi do
|
4
|
+
|
5
|
+
context "prepare repos" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
# create normal repo
|
9
|
+
repo = ::SocialSnippet::Repository::Models::Repository.create(
|
10
|
+
:name => "repo-a",
|
11
|
+
)
|
12
|
+
repo.add_ref "1.2.3", "rev-1.2.3"
|
13
|
+
repo.add_package "1.2.3"
|
14
|
+
|
15
|
+
# create package
|
16
|
+
# src/
|
17
|
+
# file/
|
18
|
+
# sub_file_1.cpp
|
19
|
+
# sub_file_2.cpp
|
20
|
+
# sub_file_3.cpp
|
21
|
+
# file.cpp
|
22
|
+
# snippet.json
|
23
|
+
package = ::SocialSnippet::Repository::Models::Package.create(
|
24
|
+
:repo_name => "repo-a",
|
25
|
+
:rev_hash => "rev-1.2.3",
|
26
|
+
)
|
27
|
+
package.add_directory "src"
|
28
|
+
package.add_directory "src/file"
|
29
|
+
package.add_file "snippet.json", {
|
30
|
+
:name => "repo-a",
|
31
|
+
:main => "src",
|
32
|
+
}.to_json
|
33
|
+
package.add_file "src/file.cpp", ""
|
34
|
+
package.add_file "src/file/sub_file_1.cpp", ""
|
35
|
+
package.add_file "src/file/sub_file_2.cpp", ""
|
36
|
+
package.add_file "src/file/sub_file_3.cpp", ""
|
37
|
+
end
|
38
|
+
|
39
|
+
before do
|
40
|
+
# create no-main repo
|
41
|
+
repo = ::SocialSnippet::Repository::Models::Repository.create(
|
42
|
+
:name => "repo-no-main",
|
43
|
+
)
|
44
|
+
repo.add_ref "0.0.0", "rev-0.0.0"
|
45
|
+
repo.add_package "0.0.0"
|
46
|
+
|
47
|
+
# create package
|
48
|
+
# file/
|
49
|
+
# sub_file.cpp
|
50
|
+
# snippet.json
|
51
|
+
# file.cpp
|
52
|
+
package = ::SocialSnippet::Repository::Models::Package.create(
|
53
|
+
:repo_name => "repo-no-main",
|
54
|
+
:rev_hash => "rev-0.0.0",
|
55
|
+
)
|
56
|
+
package.add_directory "file"
|
57
|
+
package.add_file "snippet.json", {
|
58
|
+
:name => "repo-no-main",
|
59
|
+
}.to_json
|
60
|
+
package.add_file "file.cpp", ""
|
61
|
+
package.add_file "file/sub_file.cpp", ""
|
62
|
+
end
|
63
|
+
|
64
|
+
context "complete // @snip" do
|
65
|
+
subject do
|
66
|
+
lambda { fake_core.api.complete_snippet_path "//" }
|
67
|
+
end
|
68
|
+
it { should raise_error }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "complete // @snip <" do
|
72
|
+
subject { fake_core.api.complete_snippet_path "// @snip <" }
|
73
|
+
it { should include "repo-a" }
|
74
|
+
it { should include "repo-no-main" }
|
75
|
+
end
|
76
|
+
|
77
|
+
context "complete // @snip<re" do
|
78
|
+
subject { fake_core.api.complete_snippet_path "// @snip <re" }
|
79
|
+
it { should include "repo-a" }
|
80
|
+
it { should include "repo-no-main" }
|
81
|
+
end
|
82
|
+
|
83
|
+
context "complete // @snip<repo-n" do
|
84
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-n" }
|
85
|
+
it { should_not include "repo-a" }
|
86
|
+
it { should include "repo-no-main" }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "complete // @snip<repo-a:" do
|
90
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-a:" }
|
91
|
+
it { expect(subject.length).to eq 2 }
|
92
|
+
it { should include "file.cpp>" }
|
93
|
+
it { should include "file/" }
|
94
|
+
end
|
95
|
+
|
96
|
+
context "complete // @snip<repo-a:file" do
|
97
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-a:file" }
|
98
|
+
it { expect(subject.length).to eq 2 }
|
99
|
+
it { should include "file.cpp>" }
|
100
|
+
it { should include "file/" }
|
101
|
+
end
|
102
|
+
|
103
|
+
context "complete // @snip<repo-a:file." do
|
104
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-a:file." }
|
105
|
+
it { expect(subject.length).to eq 1 }
|
106
|
+
it { should include "file.cpp>" }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "complete // @snip<repo-a:file/" do
|
110
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-a:file/" }
|
111
|
+
it { expect(subject.length).to eq 3 }
|
112
|
+
it { should include "sub_file_1.cpp>" }
|
113
|
+
it { should include "sub_file_2.cpp>" }
|
114
|
+
it { should include "sub_file_3.cpp>" }
|
115
|
+
end
|
116
|
+
|
117
|
+
context "complete // @snip <repo-no-main:" do
|
118
|
+
subject { fake_core.api.complete_snippet_path "// @snip <repo-no-main:" }
|
119
|
+
it { expect(subject.length).to eq 3 }
|
120
|
+
it { should include "file.cpp>" }
|
121
|
+
it { should include "snippet.json>" }
|
122
|
+
it { should include "file/" }
|
123
|
+
end
|
124
|
+
|
125
|
+
end # prepare repos
|
126
|
+
|
127
|
+
end # ::SocialSnippet::Api::CompletionApi
|
128
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_snippet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroyuki Sano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: version_sorter
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: highline
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -297,6 +297,7 @@ files:
|
|
297
297
|
- spec/helpers/fakefs_helper.rb
|
298
298
|
- spec/helpers/social_snippet_helper.rb
|
299
299
|
- spec/helpers/webmock_helper.rb
|
300
|
+
- spec/lib/api/completion_api_spec.rb
|
300
301
|
- spec/lib/api/insert_snippet_spec.rb
|
301
302
|
- spec/lib/api/update_repository_spec.rb
|
302
303
|
- spec/lib/command_line/sspm_config_spec.rb
|
@@ -363,6 +364,7 @@ test_files:
|
|
363
364
|
- spec/helpers/fakefs_helper.rb
|
364
365
|
- spec/helpers/social_snippet_helper.rb
|
365
366
|
- spec/helpers/webmock_helper.rb
|
367
|
+
- spec/lib/api/completion_api_spec.rb
|
366
368
|
- spec/lib/api/insert_snippet_spec.rb
|
367
369
|
- spec/lib/api/update_repository_spec.rb
|
368
370
|
- spec/lib/command_line/sspm_config_spec.rb
|