social_snippet 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +1 -2
- data/Rakefile +12 -0
- data/lib/social_snippet/api.rb +4 -4
- data/lib/social_snippet/api/completion_api.rb +1 -1
- data/lib/social_snippet/api/config_api.rb +3 -3
- data/lib/social_snippet/api/insert_snippet_api.rb +1 -1
- data/lib/social_snippet/api/install_repository_api.rb +5 -5
- data/lib/social_snippet/api/manifest_api.rb +5 -5
- data/lib/social_snippet/api/registry_api.rb +1 -1
- data/lib/social_snippet/api/search_api.rb +2 -2
- data/lib/social_snippet/api/show_api.rb +1 -1
- data/lib/social_snippet/api/update_repository_api.rb +9 -9
- data/lib/social_snippet/command_line/command.rb +2 -2
- data/lib/social_snippet/command_line/ssnip/main_command.rb +1 -1
- data/lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb +1 -1
- data/lib/social_snippet/command_line/sspm/sub_commands/config_command.rb +3 -3
- data/lib/social_snippet/command_line/sspm/sub_commands/info_command.rb +1 -1
- data/lib/social_snippet/command_line/sspm/sub_commands/init_command.rb +1 -1
- data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +4 -4
- data/lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb +2 -2
- data/lib/social_snippet/command_line/sspm/sub_commands/search_command.rb +1 -1
- data/lib/social_snippet/command_line/sspm/sub_commands/update_command.rb +2 -2
- data/lib/social_snippet/config.rb +3 -3
- data/lib/social_snippet/context.rb +32 -11
- data/lib/social_snippet/registry/registry_client.rb +4 -4
- data/lib/social_snippet/registry/registry_resources/base.rb +13 -13
- data/lib/social_snippet/repository/repository_installer.rb +6 -6
- data/lib/social_snippet/repository/repository_manager.rb +11 -12
- data/lib/social_snippet/resolvers/base_resolver.rb +25 -11
- data/lib/social_snippet/resolvers/dep_resolver.rb +4 -4
- data/lib/social_snippet/resolvers/insert_resolver.rb +14 -13
- data/lib/social_snippet/snippet.rb +76 -55
- data/lib/social_snippet/tag.rb +28 -7
- data/lib/social_snippet/tag_parser.rb +47 -38
- data/lib/social_snippet/version.rb +1 -1
- data/spec/lib/api_spec.rb +4 -4
- data/spec/lib/command_line/sspm_config_spec.rb +3 -3
- data/spec/lib/command_line/sspm_init_spec.rb +1 -1
- data/spec/lib/command_line/sspm_install_spec.rb +5 -5
- data/spec/lib/command_line/sspm_search_spec.rb +1 -1
- data/spec/lib/context_spec.rb +29 -22
- data/spec/lib/core_spec.rb +12 -12
- data/spec/lib/insert_resolver_spec.rb +7 -7
- data/spec/lib/repository/repository_manager_spec.rb +1 -0
- data/spec/spec_helper.rb +15 -15
- data/test/core_test.rb +1062 -428
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZGQwZjI1YTVhNDJiZjY2MDdkYjdiYTU5NDU0NjU1OGFiYmE5OGVlMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZmU2MjBkOGYwNTUzNTdjYjIzOGI1ZWI1ODkwY2EwOWM3YTBiMzllMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjkwMGFiNmExZDM1NGIzN2Y2ZmY5YmEyZGQ2YjUzNTdhZWY0MTBhOTFjNzRl
|
10
|
+
NTg3YjAyMGUxMjNmOWQwMjBkZTk3YjVkMzg0YzYwMDhiMTI4ZDBjZmY0MWYw
|
11
|
+
NTE3YzIwYzNlNmE4OWNmZGFlM2M4NzdmYmMxYTlhZDRiZjFkNmU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTBkNzc5OTQ1NmU0YmE3NzlmNGVjNGEyMTkxOTc4NTdhMmY3NTk2YzY2NDQy
|
14
|
+
ZDViZDEzNzUxYzg3OTY1ZjI4ZjNkM2QzYWYwODZhNTFiYzY3MzFjYzRkNmE3
|
15
|
+
NTJlMmZhNmUzNDUwNWRmOGNiODMzNzM4MDQzM2ZiNzU1YTJhNGY=
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -10,6 +10,18 @@ task :default => [:spec]
|
|
10
10
|
|
11
11
|
require "rspec/core/rake_task"
|
12
12
|
|
13
|
+
RSpec::Core::RakeTask.new(:spec_all) do |t|
|
14
|
+
ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
|
15
|
+
t.pattern = [
|
16
|
+
'spec/**/*_spec.rb',
|
17
|
+
'test/**/*_test.rb',
|
18
|
+
]
|
19
|
+
t.rspec_opts = [
|
20
|
+
"--color",
|
21
|
+
"--tag ~without_fakefs",
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
13
25
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
26
|
ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
|
15
27
|
t.rspec_opts = [
|
data/lib/social_snippet/api.rb
CHANGED
@@ -12,11 +12,11 @@ require_relative "api/registry_api"
|
|
12
12
|
|
13
13
|
class SocialSnippet::Api
|
14
14
|
|
15
|
-
attr_reader :
|
15
|
+
attr_reader :core
|
16
16
|
|
17
17
|
# Constructor
|
18
|
-
def initialize(
|
19
|
-
@
|
18
|
+
def initialize(new_core)
|
19
|
+
@core = new_core
|
20
20
|
end
|
21
21
|
|
22
22
|
include ::SocialSnippet::Api::ConfigApi
|
@@ -36,7 +36,7 @@ class SocialSnippet::Api
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def output(message)
|
39
|
-
|
39
|
+
core.logger.say message
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
@@ -2,13 +2,13 @@ module SocialSnippet::Api::ConfigApi
|
|
2
2
|
|
3
3
|
# $ sspm config key=value
|
4
4
|
def config_set(key, value)
|
5
|
-
|
5
|
+
core.config.set! key, value
|
6
6
|
end
|
7
7
|
|
8
8
|
# $ sspm config key
|
9
9
|
def config_get(key)
|
10
|
-
value =
|
11
|
-
|
10
|
+
value = core.config.get(key)
|
11
|
+
core.logger.say "#{key}=#{value}"
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
@@ -7,7 +7,7 @@ module SocialSnippet::Api::InsertSnippetApi
|
|
7
7
|
#
|
8
8
|
def insert_snippet(src, options = {})
|
9
9
|
raise "must be passed string" unless src.is_a?(String)
|
10
|
-
resolver = ::SocialSnippet::Resolvers::InsertResolver.new(
|
10
|
+
resolver = ::SocialSnippet::Resolvers::InsertResolver.new(core, options)
|
11
11
|
res = resolver.insert(src)
|
12
12
|
output res
|
13
13
|
res
|
@@ -20,7 +20,7 @@ module SocialSnippet::Api::InstallRepositoryApi
|
|
20
20
|
|
21
21
|
output "Installing: #{display_name}"
|
22
22
|
unless options[:dry_run]
|
23
|
-
|
23
|
+
core.repo_manager.install repo_name, repo_ref, repo, options
|
24
24
|
end
|
25
25
|
|
26
26
|
output "Success: #{display_name}"
|
@@ -42,13 +42,13 @@ module SocialSnippet::Api::InstallRepositoryApi
|
|
42
42
|
output "Installing as #{installed_as}"
|
43
43
|
end
|
44
44
|
|
45
|
-
if
|
45
|
+
if core.repo_manager.exists?(installed_as, repo_ref)
|
46
46
|
output "#{installed_as} is already installed"
|
47
47
|
return
|
48
48
|
end
|
49
49
|
|
50
50
|
output "Finding: #{repo_name}"
|
51
|
-
info =
|
51
|
+
info = core.registry_client.repositories.find(repo_name)
|
52
52
|
output "Found at: #{info["url"]}"
|
53
53
|
|
54
54
|
output "Cloning repository..."
|
@@ -76,7 +76,7 @@ module SocialSnippet::Api::InstallRepositoryApi
|
|
76
76
|
installed_as = options[:name] unless options[:name].nil?
|
77
77
|
output "Installing as #{installed_as}"
|
78
78
|
|
79
|
-
if
|
79
|
+
if core.repo_manager.exists?(installed_as)
|
80
80
|
output "#{installed_as} is already installed"
|
81
81
|
return
|
82
82
|
end
|
@@ -86,7 +86,7 @@ module SocialSnippet::Api::InstallRepositoryApi
|
|
86
86
|
|
87
87
|
def install_missing_dependencies(repo_deps, options = {})
|
88
88
|
repo_deps.each do |dep_repo_name, dep_repo_ref|
|
89
|
-
unless
|
89
|
+
unless core.repo_manager.exists?(dep_repo_name, dep_repo_ref)
|
90
90
|
install_repository_by_name dep_repo_name, dep_repo_ref, options
|
91
91
|
end
|
92
92
|
end
|
@@ -16,9 +16,9 @@ module SocialSnippet::Api::ManifestApi
|
|
16
16
|
def loop_manifest_questions(answer)
|
17
17
|
loop do
|
18
18
|
answer = ask_manifest_questions(manifest_questions(answer), answer)
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
core.logger.say ""
|
20
|
+
core.logger.say ::JSON.pretty_generate(answer)
|
21
|
+
core.logger.say ""
|
22
22
|
break if ask_confirm("Is this okay? [Y/N]: ")
|
23
23
|
end
|
24
24
|
answer
|
@@ -34,7 +34,7 @@ module SocialSnippet::Api::ManifestApi
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def ask_confirm(message)
|
37
|
-
ret =
|
37
|
+
ret = core.prompt.ask(message) do |q|
|
38
38
|
q.limit = 1
|
39
39
|
q.validate = /^[yn]$/i
|
40
40
|
end
|
@@ -50,7 +50,7 @@ module SocialSnippet::Api::ManifestApi
|
|
50
50
|
|
51
51
|
def ask_manifest_question(question)
|
52
52
|
if question[:type] === :string
|
53
|
-
|
53
|
+
core.prompt.ask("#{question[:key]}: ") do |q|
|
54
54
|
q.default = question[:default]
|
55
55
|
if question[:validate].is_a?(Regexp)
|
56
56
|
q.validate = question[:validate]
|
@@ -3,7 +3,7 @@ module SocialSnippet::Api::SearchApi
|
|
3
3
|
# $ sspm search query
|
4
4
|
def search_repositories(query, options = {})
|
5
5
|
format_text = search_result_format(options)
|
6
|
-
|
6
|
+
core.registry_client.repositories.search(query).each do |repo|
|
7
7
|
output format_text % search_result_list(repo, options)
|
8
8
|
end
|
9
9
|
end
|
@@ -20,7 +20,7 @@ module SocialSnippet::Api::SearchApi
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def search_result_installed(repo)
|
23
|
-
if
|
23
|
+
if core.repo_manager.exists?(repo["name"])
|
24
24
|
"#installed"
|
25
25
|
else
|
26
26
|
""
|
@@ -3,7 +3,7 @@ module SocialSnippet::Api::ShowApi
|
|
3
3
|
require "json"
|
4
4
|
|
5
5
|
def show_info(repo_name)
|
6
|
-
repo_info =
|
6
|
+
repo_info = core.registry_client.repositories.find(repo_name)
|
7
7
|
output ::JSON.pretty_generate(repo_info)
|
8
8
|
end
|
9
9
|
|
@@ -3,19 +3,19 @@ module SocialSnippet::Api::UpdateRepositoryApi
|
|
3
3
|
# Update a repository
|
4
4
|
# $ sspm update repo-name
|
5
5
|
def update_repository(repo_name, options = {})
|
6
|
-
unless
|
6
|
+
unless core.repo_manager.exists?(repo_name)
|
7
7
|
output "ERROR: #{repo_name} is not installed"
|
8
8
|
return
|
9
9
|
end
|
10
10
|
|
11
11
|
output "Fetching update for #{repo_name}"
|
12
|
-
ret =
|
12
|
+
ret = core.repo_manager.fetch(repo_name, options)
|
13
13
|
|
14
|
-
repo =
|
14
|
+
repo = core.repo_manager.find_repository(repo_name)
|
15
15
|
display_name = repo_name
|
16
16
|
|
17
17
|
# nothing to update
|
18
|
-
if ret == 0 &&
|
18
|
+
if ret == 0 && core.repo_manager.exists?(repo_name, repo.latest_version)
|
19
19
|
output "Everything up-to-date"
|
20
20
|
return
|
21
21
|
end
|
@@ -27,17 +27,17 @@ module SocialSnippet::Api::UpdateRepositoryApi
|
|
27
27
|
output "Bumping version into #{version}"
|
28
28
|
display_name = "#{repo_name}\##{version}"
|
29
29
|
repo.checkout version
|
30
|
-
|
30
|
+
core.repo_manager.update repo_name, version, repo, options
|
31
31
|
end
|
32
|
-
|
32
|
+
core.repo_manager.cache_installing_repo repo
|
33
33
|
end
|
34
34
|
|
35
35
|
output "Success #{display_name}"
|
36
36
|
|
37
37
|
# update deps
|
38
|
-
if
|
38
|
+
if core.repo_manager.has_deps?(repo_name)
|
39
39
|
output "Updating #{display_name}'s dependencies"
|
40
|
-
deps =
|
40
|
+
deps = core.repo_manager.deps(repo_name)
|
41
41
|
install_missing_dependencies deps, options
|
42
42
|
output "Finish updating #{display_name}'s dependencies"
|
43
43
|
end
|
@@ -46,7 +46,7 @@ module SocialSnippet::Api::UpdateRepositoryApi
|
|
46
46
|
# Update all installed repositories
|
47
47
|
# $ sspm update
|
48
48
|
def update_all_repositories(options = {})
|
49
|
-
|
49
|
+
core.repo_manager.each_installed_repo do |repo_name|
|
50
50
|
update_repository repo_name, options
|
51
51
|
end
|
52
52
|
end
|
@@ -28,8 +28,8 @@ class SocialSnippet::CommandLine::Command
|
|
28
28
|
@opt_parser = ::OptionParser.new
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
@
|
31
|
+
def core
|
32
|
+
@core ||= ::SocialSnippet::Core.new(input_stream, output_stream)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Define an option
|
@@ -27,14 +27,14 @@ EOF
|
|
27
27
|
if has_next_token?
|
28
28
|
key = s
|
29
29
|
value = next_token
|
30
|
-
|
30
|
+
core.api.config_set key, value
|
31
31
|
else
|
32
32
|
if has_value?(s)
|
33
33
|
key, value = s.split("=")
|
34
|
-
|
34
|
+
core.api.config_set key, value
|
35
35
|
else
|
36
36
|
key = s
|
37
|
-
|
37
|
+
core.api.config_get key
|
38
38
|
end
|
39
39
|
end
|
40
40
|
else
|
@@ -43,7 +43,7 @@ EOF
|
|
43
43
|
def install_by_snippet_json
|
44
44
|
snippet_json = ::JSON.parse(File.read("snippet.json"))
|
45
45
|
snippet_json["dependencies"].each do |name, ref|
|
46
|
-
|
46
|
+
core.api.install_repository_by_name name, ref, options
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -52,15 +52,15 @@ EOF
|
|
52
52
|
token_str = next_token
|
53
53
|
if is_name?(token_str)
|
54
54
|
repo_info = parse_repo_token(token_str)
|
55
|
-
|
55
|
+
core.api.install_repository_by_name repo_info[:name], repo_info[:ref], options
|
56
56
|
elsif is_url?(token_str)
|
57
57
|
repo_info = parse_repo_token(token_str)
|
58
58
|
repo_url = repo_info[:name]
|
59
|
-
|
59
|
+
core.api.install_repository_by_url repo_url, repo_info[:ref], options
|
60
60
|
elsif is_path?(token_str)
|
61
61
|
repo_info = parse_repo_token(token_str)
|
62
62
|
repo_path = repo_info[:name]
|
63
|
-
|
63
|
+
core.api.install_repository_by_path repo_path, repo_info[:ref], options
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -33,11 +33,11 @@ EOF
|
|
33
33
|
if has_next_token?
|
34
34
|
repo_url = next_token
|
35
35
|
if /^(git|http|https)\:\/\// === repo_url # url
|
36
|
-
|
36
|
+
core.api.add_url repo_url
|
37
37
|
elsif has_next_token? # {repo_owner_id} {repo_id}
|
38
38
|
owner_id = repo_url
|
39
39
|
repo_id = next_token
|
40
|
-
|
40
|
+
core.api.add_url "https://github.com/#{owner_id}/#{repo_id}.git"
|
41
41
|
else
|
42
42
|
help
|
43
43
|
end
|
@@ -25,10 +25,10 @@ EOF
|
|
25
25
|
def run
|
26
26
|
if has_next_token?
|
27
27
|
while has_next_token?
|
28
|
-
|
28
|
+
core.api.update_repository next_token, options
|
29
29
|
end
|
30
30
|
else
|
31
|
-
|
31
|
+
core.api.update_all_repositories options
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -2,7 +2,7 @@ class SocialSnippet::Config
|
|
2
2
|
|
3
3
|
require "json"
|
4
4
|
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :core
|
6
6
|
attr_reader :home
|
7
7
|
attr_reader :fields
|
8
8
|
|
@@ -26,8 +26,8 @@ class SocialSnippet::Config
|
|
26
26
|
]
|
27
27
|
|
28
28
|
# Constructor
|
29
|
-
def initialize(
|
30
|
-
@
|
29
|
+
def initialize(new_core, options = {})
|
30
|
+
@core = new_core
|
31
31
|
@fields = {}
|
32
32
|
resolve_home
|
33
33
|
|