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.
Files changed (48) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +1 -2
  3. data/Rakefile +12 -0
  4. data/lib/social_snippet/api.rb +4 -4
  5. data/lib/social_snippet/api/completion_api.rb +1 -1
  6. data/lib/social_snippet/api/config_api.rb +3 -3
  7. data/lib/social_snippet/api/insert_snippet_api.rb +1 -1
  8. data/lib/social_snippet/api/install_repository_api.rb +5 -5
  9. data/lib/social_snippet/api/manifest_api.rb +5 -5
  10. data/lib/social_snippet/api/registry_api.rb +1 -1
  11. data/lib/social_snippet/api/search_api.rb +2 -2
  12. data/lib/social_snippet/api/show_api.rb +1 -1
  13. data/lib/social_snippet/api/update_repository_api.rb +9 -9
  14. data/lib/social_snippet/command_line/command.rb +2 -2
  15. data/lib/social_snippet/command_line/ssnip/main_command.rb +1 -1
  16. data/lib/social_snippet/command_line/sspm/sub_commands/complete_command.rb +1 -1
  17. data/lib/social_snippet/command_line/sspm/sub_commands/config_command.rb +3 -3
  18. data/lib/social_snippet/command_line/sspm/sub_commands/info_command.rb +1 -1
  19. data/lib/social_snippet/command_line/sspm/sub_commands/init_command.rb +1 -1
  20. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +4 -4
  21. data/lib/social_snippet/command_line/sspm/sub_commands/publish_command.rb +2 -2
  22. data/lib/social_snippet/command_line/sspm/sub_commands/search_command.rb +1 -1
  23. data/lib/social_snippet/command_line/sspm/sub_commands/update_command.rb +2 -2
  24. data/lib/social_snippet/config.rb +3 -3
  25. data/lib/social_snippet/context.rb +32 -11
  26. data/lib/social_snippet/registry/registry_client.rb +4 -4
  27. data/lib/social_snippet/registry/registry_resources/base.rb +13 -13
  28. data/lib/social_snippet/repository/repository_installer.rb +6 -6
  29. data/lib/social_snippet/repository/repository_manager.rb +11 -12
  30. data/lib/social_snippet/resolvers/base_resolver.rb +25 -11
  31. data/lib/social_snippet/resolvers/dep_resolver.rb +4 -4
  32. data/lib/social_snippet/resolvers/insert_resolver.rb +14 -13
  33. data/lib/social_snippet/snippet.rb +76 -55
  34. data/lib/social_snippet/tag.rb +28 -7
  35. data/lib/social_snippet/tag_parser.rb +47 -38
  36. data/lib/social_snippet/version.rb +1 -1
  37. data/spec/lib/api_spec.rb +4 -4
  38. data/spec/lib/command_line/sspm_config_spec.rb +3 -3
  39. data/spec/lib/command_line/sspm_init_spec.rb +1 -1
  40. data/spec/lib/command_line/sspm_install_spec.rb +5 -5
  41. data/spec/lib/command_line/sspm_search_spec.rb +1 -1
  42. data/spec/lib/context_spec.rb +29 -22
  43. data/spec/lib/core_spec.rb +12 -12
  44. data/spec/lib/insert_resolver_spec.rb +7 -7
  45. data/spec/lib/repository/repository_manager_spec.rb +1 -0
  46. data/spec/spec_helper.rb +15 -15
  47. data/test/core_test.rb +1062 -428
  48. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzU5NTJjOWRhNjY0MGQ1Yjk2MzY0YjA3ZmU3YTc3NzkzYjBjYWM4Mg==
4
+ ZGQwZjI1YTVhNDJiZjY2MDdkYjdiYTU5NDU0NjU1OGFiYmE5OGVlMw==
5
5
  data.tar.gz: !binary |-
6
- ZWIxMDM3ODY5MTgxYzEyMGU0ZWM4ZWNjNWFjZWJkMjg5ODgyYWQ5OA==
6
+ ZmU2MjBkOGYwNTUzNTdjYjIzOGI1ZWI1ODkwY2EwOWM3YTBiMzllMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDlhNWY2ZDMyOWZhNzRiNGQ2NzUxZGNkOWUyNGNlNGE5ZmE1MDBiZTBkMGVj
10
- ZGU0ZjViN2MxMDU0ZjlhYmZkZDcwYTI1MzYyYWVkMTUwMDM5NDJjMjA3ODlj
11
- MTk0ZGYyOTVkNWQ4Yjk4OGZhMzFmOWQxNmVjMzhkN2NlMTY2Y2U=
9
+ YjkwMGFiNmExZDM1NGIzN2Y2ZmY5YmEyZGQ2YjUzNTdhZWY0MTBhOTFjNzRl
10
+ NTg3YjAyMGUxMjNmOWQwMjBkZTk3YjVkMzg0YzYwMDhiMTI4ZDBjZmY0MWYw
11
+ NTE3YzIwYzNlNmE4OWNmZGFlM2M4NzdmYmMxYTlhZDRiZjFkNmU=
12
12
  data.tar.gz: !binary |-
13
- YTJiY2ZjZWFjYWFkNTZmNGIxMzA4Yjk1Mzc0NzgwNWRhZjFiMjM5OTFhZGZm
14
- Mzk3NTg0NmUwZTY2MzIwYjI0NzI3MzZkNTE5MjkwOGFlNDI4MzUzYjdjNDMw
15
- ODNlNjkzMTdkODU4ZTc3NzNkNTUyOTk1YmNiMWQzZmI0MjY0Mjg=
13
+ YTBkNzc5OTQ1NmU0YmE3NzlmNGVjNGEyMTkxOTc4NTdhMmY3NTk2YzY2NDQy
14
+ ZDViZDEzNzUxYzg3OTY1ZjI4ZjNkM2QzYWYwODZhNTFiYzY3MzFjYzRkNmE3
15
+ NTJlMmZhNmUzNDUwNWRmOGNiODMzNzM4MDQzM2ZiNzU1YTJhNGY=
data/.travis.yml CHANGED
@@ -11,9 +11,8 @@ bundler_args: "--without debug --jobs 3"
11
11
  sudo: false
12
12
 
13
13
  script:
14
- - bundle exec rake spec
14
+ - bundle exec rake spec_all
15
15
  - bundle exec rake spec_without_fakefs
16
- - bundle exec rake test
17
16
  - bundle exec rake test_without_fakefs
18
17
 
19
18
  deploy:
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 = [
@@ -12,11 +12,11 @@ require_relative "api/registry_api"
12
12
 
13
13
  class SocialSnippet::Api
14
14
 
15
- attr_reader :social_snippet
15
+ attr_reader :core
16
16
 
17
17
  # Constructor
18
- def initialize(new_social_snippet)
19
- @social_snippet = new_social_snippet
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
- social_snippet.logger.say message
39
+ core.logger.say message
40
40
  end
41
41
 
42
42
  end
@@ -1,7 +1,7 @@
1
1
  module SocialSnippet::Api::CompletionApi
2
2
 
3
3
  def complete_snippet_path(keyword)
4
- social_snippet.repo_manager.complete(keyword)
4
+ core.repo_manager.complete(keyword)
5
5
  end
6
6
 
7
7
  def cli_complete_snippet_path(keyword)
@@ -2,13 +2,13 @@ module SocialSnippet::Api::ConfigApi
2
2
 
3
3
  # $ sspm config key=value
4
4
  def config_set(key, value)
5
- social_snippet.config.set! key, value
5
+ core.config.set! key, value
6
6
  end
7
7
 
8
8
  # $ sspm config key
9
9
  def config_get(key)
10
- value = social_snippet.config.get(key)
11
- social_snippet.logger.say "#{key}=#{value}"
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(social_snippet, options)
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
- social_snippet.repo_manager.install repo_name, repo_ref, repo, options
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 social_snippet.repo_manager.exists?(installed_as, repo_ref)
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 = social_snippet.registry_client.repositories.find(repo_name)
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 social_snippet.repo_manager.exists?(installed_as)
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 social_snippet.repo_manager.exists?(dep_repo_name, dep_repo_ref)
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
- social_snippet.logger.say ""
20
- social_snippet.logger.say ::JSON.pretty_generate(answer)
21
- social_snippet.logger.say ""
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 = social_snippet.prompt.ask(message) do |q|
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
- social_snippet.prompt.ask("#{question[:key]}: ") do |q|
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]
@@ -1,7 +1,7 @@
1
1
  module SocialSnippet::Api::RegistryApi
2
2
 
3
3
  def add_url(url, options = {})
4
- ret = social_snippet.registry_client.repositories.add_url(url)
4
+ ret = core.registry_client.repositories.add_url(url)
5
5
  output ret
6
6
  end
7
7
 
@@ -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
- social_snippet.registry_client.repositories.search(query).each do |repo|
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 social_snippet.repo_manager.exists?(repo["name"])
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 = social_snippet.registry_client.repositories.find(repo_name)
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 social_snippet.repo_manager.exists?(repo_name)
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 = social_snippet.repo_manager.fetch(repo_name, options)
12
+ ret = core.repo_manager.fetch(repo_name, options)
13
13
 
14
- repo = social_snippet.repo_manager.find_repository(repo_name)
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 && social_snippet.repo_manager.exists?(repo_name, repo.latest_version)
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
- social_snippet.repo_manager.update repo_name, version, repo, options
30
+ core.repo_manager.update repo_name, version, repo, options
31
31
  end
32
- social_snippet.repo_manager.cache_installing_repo repo
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 social_snippet.repo_manager.has_deps?(repo_name)
38
+ if core.repo_manager.has_deps?(repo_name)
39
39
  output "Updating #{display_name}'s dependencies"
40
- deps = social_snippet.repo_manager.deps(repo_name)
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
- social_snippet.repo_manager.each_installed_repo do |repo_name|
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 social_snippet
32
- @social_snippet ||= ::SocialSnippet::Core.new(input_stream, output_stream)
31
+ def core
32
+ @core ||= ::SocialSnippet::Core.new(input_stream, output_stream)
33
33
  end
34
34
 
35
35
  # Define an option
@@ -18,7 +18,7 @@ EOF
18
18
  end
19
19
 
20
20
  def run
21
- social_snippet.api.insert_snippet(input_stream.read)
21
+ core.api.insert_snippet(input_stream.read)
22
22
  end
23
23
 
24
24
  end
@@ -17,7 +17,7 @@ EOF
17
17
 
18
18
  def run
19
19
  if has_next_token?
20
- social_snippet.api.cli_complete_snippet_path next_token
20
+ core.api.cli_complete_snippet_path next_token
21
21
  else
22
22
  help
23
23
  end
@@ -27,14 +27,14 @@ EOF
27
27
  if has_next_token?
28
28
  key = s
29
29
  value = next_token
30
- social_snippet.api.config_set key, value
30
+ core.api.config_set key, value
31
31
  else
32
32
  if has_value?(s)
33
33
  key, value = s.split("=")
34
- social_snippet.api.config_set key, value
34
+ core.api.config_set key, value
35
35
  else
36
36
  key = s
37
- social_snippet.api.config_get key
37
+ core.api.config_get key
38
38
  end
39
39
  end
40
40
  else
@@ -17,7 +17,7 @@ EOF
17
17
 
18
18
  def run
19
19
  if has_next_token?
20
- social_snippet.api.show_info next_token
20
+ core.api.show_info next_token
21
21
  else
22
22
  help
23
23
  end
@@ -19,7 +19,7 @@ EOF
19
19
  end
20
20
 
21
21
  def run
22
- social_snippet.api.init_manifest options
22
+ core.api.init_manifest options
23
23
  end
24
24
 
25
25
  end
@@ -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
- social_snippet.api.install_repository_by_name name, ref, options
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
- social_snippet.api.install_repository_by_name repo_info[:name], repo_info[:ref], options
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
- social_snippet.api.install_repository_by_url repo_url, repo_info[:ref], options
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
- social_snippet.api.install_repository_by_path repo_path, repo_info[:ref], options
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
- social_snippet.api.add_url repo_url
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
- social_snippet.api.add_url "https://github.com/#{owner_id}/#{repo_id}.git"
40
+ core.api.add_url "https://github.com/#{owner_id}/#{repo_id}.git"
41
41
  else
42
42
  help
43
43
  end
@@ -21,7 +21,7 @@ EOF
21
21
 
22
22
  def run
23
23
  if has_next_token?
24
- social_snippet.api.search_repositories next_token, options
24
+ core.api.search_repositories next_token, options
25
25
  else
26
26
  help
27
27
  end
@@ -25,10 +25,10 @@ EOF
25
25
  def run
26
26
  if has_next_token?
27
27
  while has_next_token?
28
- social_snippet.api.update_repository next_token, options
28
+ core.api.update_repository next_token, options
29
29
  end
30
30
  else
31
- social_snippet.api.update_all_repositories options
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 :social_snippet
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(new_social_snippet, options = {})
30
- @social_snippet = new_social_snippet
29
+ def initialize(new_core, options = {})
30
+ @core = new_core
31
31
  @fields = {}
32
32
  resolve_home
33
33