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.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +11 -4
  3. data/README.md +6 -6
  4. data/Rakefile +19 -1
  5. data/lib/social_snippet.rb +11 -0
  6. data/lib/social_snippet/api/install_repository_api.rb +23 -82
  7. data/lib/social_snippet/api/manifest_api.rb +3 -3
  8. data/lib/social_snippet/api/update_repository_api.rb +34 -35
  9. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +7 -7
  10. data/lib/social_snippet/config.rb +18 -8
  11. data/lib/social_snippet/core.rb +13 -0
  12. data/lib/social_snippet/document.rb +2 -0
  13. data/lib/social_snippet/document_backend.rb +2 -0
  14. data/lib/social_snippet/document_backend/yaml_document.rb +252 -0
  15. data/lib/social_snippet/document_backend/yaml_document/query.rb +45 -0
  16. data/lib/social_snippet/repository.rb +2 -2
  17. data/lib/social_snippet/repository/driver_factory.rb +42 -0
  18. data/lib/social_snippet/repository/drivers.rb +3 -2
  19. data/lib/social_snippet/repository/drivers/driver_base.rb +100 -0
  20. data/lib/social_snippet/repository/drivers/entry.rb +11 -0
  21. data/lib/social_snippet/repository/drivers/git_driver.rb +100 -0
  22. data/lib/social_snippet/repository/models.rb +15 -0
  23. data/lib/social_snippet/repository/models/package.rb +97 -0
  24. data/lib/social_snippet/repository/models/repository.rb +94 -0
  25. data/lib/social_snippet/repository/repository_manager.rb +79 -67
  26. data/lib/social_snippet/resolvers/base_resolver.rb +13 -17
  27. data/lib/social_snippet/rspec/test_document.rb +305 -0
  28. data/lib/social_snippet/rspec/test_driver.rb +76 -0
  29. data/lib/social_snippet/rspec/test_storage.rb +459 -0
  30. data/lib/social_snippet/storage.rb +1 -0
  31. data/lib/social_snippet/storage_backend.rb +3 -0
  32. data/lib/social_snippet/storage_backend/file_system_storage.rb +71 -0
  33. data/lib/social_snippet/storage_backend/storage_base.rb +35 -0
  34. data/lib/social_snippet/version.rb +8 -3
  35. data/spec/helpers/codeclimate_helper.rb +1 -1
  36. data/spec/helpers/fakefs_helper.rb +10 -0
  37. data/spec/helpers/social_snippet_helper.rb +117 -0
  38. data/spec/lib/api/insert_snippet_spec.rb +95 -2
  39. data/spec/lib/api/update_repository_spec.rb +196 -0
  40. data/spec/lib/command_line/sspm_install_spec.rb +169 -180
  41. data/spec/lib/command_line/sspm_update_spec.rb +56 -0
  42. data/spec/lib/config_spec.rb +6 -8
  43. data/spec/lib/core_spec.rb +21 -38
  44. data/spec/lib/file_system_storage_spec.rb +170 -0
  45. data/spec/lib/insert_resolver_spec.rb +15 -2
  46. data/spec/lib/registry_client_spec.rb +6 -9
  47. data/spec/lib/repository/driver_base_spec.rb +89 -0
  48. data/spec/lib/repository/git_driver_spec.rb +10 -0
  49. data/spec/lib/repository/package_spec.rb +172 -0
  50. data/spec/lib/repository/repository_factory_spec.rb +67 -22
  51. data/spec/lib/repository/repository_manager_spec.rb +71 -114
  52. data/spec/lib/repository/repository_spec.rb +191 -0
  53. data/spec/lib/yaml_document_spec.rb +14 -0
  54. data/spec/spec_helper.rb +8 -93
  55. data/test/config_test.rb +6 -7
  56. data/test/driver_base_test.rb +201 -0
  57. data/test/git_driver_test.rb +51 -0
  58. data/test/insert_snippet_test.rb +256 -349
  59. data/test/repository_manager_test.rb +7 -16
  60. data/test/yaml_document_test.rb +97 -0
  61. metadata +44 -16
  62. data/lib/social_snippet/repository/drivers/base_repository.rb +0 -189
  63. data/lib/social_snippet/repository/drivers/git_repository.rb +0 -74
  64. data/lib/social_snippet/repository/repository_factory.rb +0 -59
  65. data/lib/social_snippet/repository/repository_installer.rb +0 -85
  66. data/spec/lib/repository/base_repository_spec.rb +0 -104
  67. data/spec/lib/repository/git_repository_spec.rb +0 -83
  68. data/spec/lib/repository/repository_installer_spec.rb +0 -63
  69. data/test/base_repository_test.rb +0 -375
  70. data/test/git_repository_test.rb +0 -114
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjJjNzJiN2EzNjk0Yzk3MjA0ODU3YWRiODIxYzE0NDYyNjZmODg3Nw==
4
+ ZjU4NjgyZmM4MWYyZmRlOWZlNGQ1YmJmNzI0MzExOGI4MmQxODVjOA==
5
5
  data.tar.gz: !binary |-
6
- NjA2MGEwNzEzZjk3NjZkMGEzMTE4ZGU5MzM1OWIxMmJjNjY4MzU5Yg==
6
+ NGJlMGFlOGYzMGViMDk0NzU3MjVkN2M3YmIyMDJiYjVmNWQzYTZkYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzVlYzRiZmQwM2MyZGM3ZWY5YjkxMjU4OGRlMmIzYjQyMmI0YmY1NzM3YTBl
10
- OTBkYjBhMDliYTJjMzkyMjg2YWM0MjI3MDkzODA1MmY5M2Q1ZmRlNWZjYTdk
11
- MTBjZTA1NDE4ZjljNGQ0ZTBkMDAwMWIxZjY3YjEwN2UzMDMyZmE=
9
+ Y2EyZGYwMDhjOTkyOTcyZWM0YzYxMDI2ZjE3YTM3M2NmZWE2N2NjMmE4Nzg2
10
+ MThjMjQ4Y2IxOGQ2NjNkNzM5MjMzMDdmYjAwZWJiNGQyMGM5Yjg0MGI1ZGQ2
11
+ OTM0Mjc3OThhOWJjMTAwZmE0N2I2OWNhZmFmMjkxOTJkYTcyN2I=
12
12
  data.tar.gz: !binary |-
13
- MDQxZWI2MDMyOTA0ODhkNTBiN2FmMjUxZDBhNjdiYjI1NzJjMjcwYzE0YmMy
14
- NWIzMTgwZDkzZjA5YTllZWNkZmMzY2Q4YzFmNDZhZTU0NWJhM2ViYjBkNDYw
15
- NWUyZjRhYmUxZTg4OWQzZThhNWY4ZDk4N2VhNzI5Zjg4YTZlODU=
13
+ OTZmNzRhZTI4NmU4N2U1OThkYmNhYzdiNGJmMTA3MWQwZjU3Y2FmMGM4ZmU2
14
+ MDZlMGE2OWUwZmI0ODk1OWQ4NWZkNDdlN2VmMWFjNTk2Nzc1NmQxOGEwOWI3
15
+ MGI2NTg0MGJmY2Y5Y2M2YjE1YTUyOWY3MWM2ZmJmZWY3ZGRiMDU=
@@ -10,17 +10,24 @@ bundler_args: "--without debug --jobs 3"
10
10
 
11
11
  sudo: false
12
12
 
13
+ env:
14
+ global:
15
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=YES
16
+
13
17
  script:
14
- - bundle exec rake spec_all
15
- - bundle exec rake spec_without_fakefs
16
- - bundle exec rake test_without_fakefs
18
+ - bundle exec rake spec spec_all_without_fakefs
17
19
 
18
20
  # shell access test
19
21
  - bundle exec rake build
20
22
  - gem install pkg/social_snippet-*.gem
21
- - sspm install example-repo
23
+ - export SOCIAL_SNIPPET_HOME=$HOME/.social-snippet-test
24
+ - export SOCIAL_SNIPPET_DEBUG=true
25
+ - sspm install example-repo#1.0.0
26
+ - echo "// @snip <example-repo:func.cpp>" | ssnip
22
27
  - sspm update
23
28
  - echo "// @snip <example-repo:func.cpp>" | ssnip
29
+ - unset SOCIAL_SNIPPET_HOME
30
+ - unset SOCIAL_SNIPPET_DEBUG
24
31
 
25
32
  deploy:
26
33
  provider: rubygems
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Social Snippet
2
2
 
3
- [![Gem Version](https://img.shields.io/gem/v/social_snippet.svg?style=flat)](https://rubygems.org/gems/social_snippet)
4
- [![Build Status](https://img.shields.io/travis/social-snippet/social-snippet.svg?style=flat)](https://travis-ci.org/social-snippet/social-snippet)
5
- [![Code Climate](https://img.shields.io/codeclimate/github/social-snippet/social-snippet.svg?style=flat)](https://codeclimate.com/github/social-snippet/social-snippet)
6
- [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/social-snippet/social-snippet.svg?style=flat)](https://codeclimate.com/github/social-snippet/social-snippet)
7
- [![API Doc](http://img.shields.io/badge/RubyDocs-API-green.svg?style=flat)](http://www.rubydoc.info/github/social-snippet/social-snippet)
8
- [![Dependencies Status](https://img.shields.io/gemnasium/social-snippet/social-snippet.svg)](https://gemnasium.com/social-snippet/social-snippet)
3
+ [![Gem Version](https://img.shields.io/gem/v/social_snippet.svg?style=flat-square)](https://rubygems.org/gems/social_snippet)
4
+ [![Build Status](https://img.shields.io/travis/social-snippet/social-snippet.svg?style=flat-square)](https://travis-ci.org/social-snippet/social-snippet)
5
+ [![Code Climate](https://img.shields.io/codeclimate/github/social-snippet/social-snippet.svg?style=flat-square)](https://codeclimate.com/github/social-snippet/social-snippet)
6
+ [![Test Coverage](https://img.shields.io/codeclimate/coverage/github/social-snippet/social-snippet.svg?style=flat-square)](https://codeclimate.com/github/social-snippet/social-snippet)
7
+ [![API Doc](http://img.shields.io/badge/RubyDocs-API-green.svg?style=flat-square)](http://www.rubydoc.info/github/social-snippet/social-snippet)
8
+ [![Dependencies Status](https://img.shields.io/gemnasium/social-snippet/social-snippet.svg?style=flat-square)](https://gemnasium.com/social-snippet/social-snippet)
9
9
 
10
10
  TODO: Write a gem description
11
11
 
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ require "rspec/core/rake_task"
12
12
 
13
13
  RSpec::Core::RakeTask.new(:spec_all) do |t|
14
14
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
15
+ ENV["ENABLE_CODECLIMATE"] = "false"
15
16
  t.pattern = [
16
17
  'spec/**/*_spec.rb',
17
18
  'test/**/*_test.rb',
@@ -22,8 +23,21 @@ RSpec::Core::RakeTask.new(:spec_all) do |t|
22
23
  ]
23
24
  end
24
25
 
26
+ RSpec::Core::RakeTask.new(:spec_all_without_fakefs) do |t|
27
+ ENV["RSPEC_WITHOUT_FAKEFS"] = "true"
28
+ ENV["ENABLE_CODECLIMATE"] = "true"
29
+ t.pattern = [
30
+ 'spec/**/*_spec.rb',
31
+ 'test/**/*_test.rb',
32
+ ]
33
+ t.rspec_opts = [
34
+ "--color",
35
+ ]
36
+ end
37
+
25
38
  RSpec::Core::RakeTask.new(:spec) do |t|
26
39
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
40
+ ENV["ENABLE_CODECLIMATE"] = "false"
27
41
  t.rspec_opts = [
28
42
  "--format documentation",
29
43
  "--color",
@@ -33,16 +47,17 @@ end
33
47
 
34
48
  RSpec::Core::RakeTask.new(:spec_current) do |t|
35
49
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
50
+ ENV["ENABLE_CODECLIMATE"] = "false"
36
51
  t.rspec_opts = [
37
52
  "--format documentation",
38
53
  "--color",
39
- "--tag ~without_fakefs",
40
54
  "--tag current",
41
55
  ]
42
56
  end
43
57
 
44
58
  RSpec::Core::RakeTask.new(:spec_without_fakefs) do |t|
45
59
  ENV["RSPEC_WITHOUT_FAKEFS"] = "true"
60
+ ENV["ENABLE_CODECLIMATE"] = "false"
46
61
  t.rspec_opts = [
47
62
  "--format documentation",
48
63
  "--color",
@@ -52,6 +67,7 @@ end
52
67
 
53
68
  RSpec::Core::RakeTask.new(:test) do |t|
54
69
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
70
+ ENV["ENABLE_CODECLIMATE"] = "false"
55
71
  t.rspec_opts = [
56
72
  "--pattern '../test/*_test.rb'",
57
73
  "--color",
@@ -61,6 +77,7 @@ end
61
77
 
62
78
  RSpec::Core::RakeTask.new(:test_current) do |t|
63
79
  ENV["RSPEC_WITHOUT_FAKEFS"] = "false"
80
+ ENV["ENABLE_CODECLIMATE"] = "false"
64
81
  t.rspec_opts = [
65
82
  "--pattern '../test/*_test.rb'",
66
83
  "--color",
@@ -71,6 +88,7 @@ end
71
88
 
72
89
  RSpec::Core::RakeTask.new(:test_without_fakefs) do |t|
73
90
  ENV["RSPEC_WITHOUT_FAKEFS"] = "true"
91
+ ENV["ENABLE_CODECLIMATE"] = "false"
74
92
  t.rspec_opts = [
75
93
  "--pattern '../test/*_test.rb'",
76
94
  "--color",
@@ -10,6 +10,7 @@ require "optparse"
10
10
  require "uri"
11
11
  require "rugged"
12
12
  require "wisper"
13
+ require "securerandom"
13
14
 
14
15
  module SocialSnippet; end
15
16
  require_relative "social_snippet/core"
@@ -27,3 +28,13 @@ require_relative "social_snippet/command_line"
27
28
  require_relative "social_snippet/logger"
28
29
  require_relative "social_snippet/api"
29
30
  require_relative "social_snippet/tsortable_hash"
31
+ require_relative "social_snippet/storage_backend"
32
+ require_relative "social_snippet/storage"
33
+ require_relative "social_snippet/document_backend"
34
+ require_relative "social_snippet/document"
35
+
36
+ # use file system as default storage backend
37
+ SocialSnippet::StorageBackend::FileSystemStorage.activate!
38
+ # use yaml as default document backend
39
+ SocialSnippet::DocumentBackend::YAMLDocument.activate!
40
+
@@ -1,109 +1,50 @@
1
1
  module SocialSnippet::Api::InstallRepositoryApi
2
2
 
3
- # Install repository (Core API)
4
- #
5
- # @param repo [::SocialSnippet::Repository::Drivers::BaseRepository]
6
- def install_repository(repo_name, repo_ref, repo, options = {})
7
- display_name = repo_name
8
-
9
- if repo_ref.nil?
10
- repo_ref = resolve_reference(repo)
11
-
12
- if repo.has_versions?
13
- output "Resolving #{display_name}'s version"
14
- else
15
- output "No versions, use current reference"
16
- end
17
- end
18
-
19
- display_name = "#{repo_name}\##{repo_ref}"
20
-
21
- output "Installing: #{display_name}"
22
- unless options[:dry_run]
23
- core.repo_manager.install repo_name, repo_ref, repo, options
24
- end
25
-
26
- output "Success: #{display_name}"
27
-
28
- # install dependencies
29
- if has_dependencies?(repo)
30
- output "Finding #{display_name}'s dependencies"
31
- install_missing_dependencies repo.dependencies, options
32
- output "Finish finding #{display_name}'s dependencies"
33
- end
34
- end
35
-
36
- # $ sspm install name
37
- def install_repository_by_name(repo_name, repo_ref, options = {})
38
- installed_as = repo_name
39
- installed_as = options[:name] unless options[:name].nil?
40
-
41
- unless installed_as === repo_name
42
- output "Installing as #{installed_as}"
43
- end
44
-
45
- if core.repo_manager.exists?(installed_as, repo_ref)
46
- output "#{installed_as} is already installed"
47
- return
48
- end
49
-
50
- output "Finding: #{repo_name}"
3
+ def resolve_name_by_registry(repo_name)
4
+ output "Finding #{repo_name}..."
51
5
  info = core.registry_client.repositories.find(repo_name)
52
- output "Found at: #{info["url"]}"
53
-
54
- output "Cloning repository..."
55
- repo = ::SocialSnippet::Repository::RepositoryFactory.clone(info["url"])
56
-
57
- install_repository installed_as, repo_ref, repo
58
- end
59
-
60
- # $ sspm install URL
61
- def install_repository_by_url(repo_url, repo_ref, options = {})
62
- output "Cloning repository..."
63
- repo = ::SocialSnippet::Repository::RepositoryFactory.clone(repo_url)
64
- install_repository_by_repo repo, repo_ref, options
6
+ output "Found at #{info["url"]}"
7
+ info["url"]
65
8
  end
66
9
 
67
- # $ sspm install ./path/to/repo
68
- def install_repository_by_path(repo_path, repo_ref, options = {})
69
- output "Cloning repository..."
70
- repo = ::SocialSnippet::Repository::RepositoryFactory.clone_local(repo_path)
71
- install_repository_by_repo repo, repo_ref, options
72
- end
73
-
74
- def install_repository_by_repo(repo, repo_ref, options)
75
- installed_as = repo.name
76
- installed_as = options[:name] unless options[:name].nil?
77
- output "Installing as #{installed_as}"
10
+ # Install repository
11
+ #
12
+ # @param url [String]
13
+ # @param ref [String]
14
+ def install_repository(url, ref, options = {})
15
+ output "Fetching #{url}..."
78
16
 
79
- if core.repo_manager.exists?(installed_as)
80
- output "#{installed_as} is already installed"
81
- return
17
+ unless options[:dry_run]
18
+ package = core.repo_manager.install(url, ref, options)
82
19
  end
20
+ output "Success #{package.display_name}"
83
21
 
84
- install_repository installed_as, repo_ref, repo
22
+ if package.has_dependencies?
23
+ output "Finding package dependencies..."
24
+ install_missing_dependencies package.dependencies, options
25
+ output "Finished finding package dependencies."
26
+ end
85
27
  end
86
28
 
87
29
  def install_missing_dependencies(repo_deps, options = {})
88
30
  repo_deps.each do |dep_repo_name, dep_repo_ref|
89
31
  unless core.repo_manager.exists?(dep_repo_name, dep_repo_ref)
90
- install_repository_by_name dep_repo_name, dep_repo_ref, options
32
+ url = resolve_name_by_registry(dep_repo_name)
33
+ install_repository url, dep_repo_ref, options
91
34
  end
92
35
  end
93
36
  end
94
37
 
95
38
  private
96
39
 
97
- def resolve_reference(repo)
40
+ def resolve_reference_by_repo(repo)
98
41
  if repo.has_versions?
42
+ output "Resolving #{display_name}'s version"
99
43
  repo.latest_version
100
44
  else
45
+ output "No versions, use current reference"
101
46
  repo.current_ref
102
47
  end
103
48
  end
104
49
 
105
- def has_dependencies?(repo)
106
- repo.dependencies && ( not repo.dependencies.empty? )
107
- end
108
-
109
50
  end
@@ -5,7 +5,7 @@ module SocialSnippet::Api::ManifestApi
5
5
  def init_manifest(options = {})
6
6
  current_answers = load_manifest_file || {}
7
7
  answer = loop_manifest_questions(current_answers)
8
- ::File.write "snippet.json", ::JSON.pretty_generate(answer)
8
+ core.storage.write "snippet.json", ::JSON.pretty_generate(answer)
9
9
  answer
10
10
  end
11
11
 
@@ -24,8 +24,8 @@ module SocialSnippet::Api::ManifestApi
24
24
 
25
25
  # load current configuration
26
26
  def load_manifest_file
27
- if ::File.exists?("snippet.json")
28
- ::JSON.parse(::File.read "snippet.json")
27
+ if core.storage.exists?("snippet.json")
28
+ ::JSON.parse(core.storage.read "snippet.json")
29
29
  else
30
30
  nil
31
31
  end
@@ -2,53 +2,52 @@ module SocialSnippet::Api::UpdateRepositoryApi
2
2
 
3
3
  # Update a repository
4
4
  # $ sspm update repo-name
5
- def update_repository(repo_name, options = {})
6
- unless core.repo_manager.exists?(repo_name)
7
- output "ERROR: #{repo_name} is not installed"
8
- return
5
+ def update_repository(name, options = {})
6
+ unless core.repo_manager.exists?(name)
7
+ raise "ERROR: #{name} is not installed"
9
8
  end
10
9
 
11
- output "Fetching update for #{repo_name}"
12
- ret = core.repo_manager.fetch(repo_name, options)
10
+ output "Fetching update for #{name}"
11
+ repo = core.repo_manager.find_repository(name)
12
+ driver = core.driver_factory.clone(repo.url)
13
+ # reload repository
14
+ repo = core.repo_manager.update_repository(driver, repo.url)
13
15
 
14
- repo = core.repo_manager.find_repository(repo_name)
15
- display_name = repo_name
16
-
17
- # nothing to update
18
- if ret == 0 && core.repo_manager.exists?(repo_name, repo.latest_version)
16
+ unless update_repository_for_each_minor_version(driver, repo, options)
19
17
  output "Everything up-to-date"
20
- return
21
18
  end
19
+ end
22
20
 
23
- output "Updating #{repo_name}"
24
- unless options[:dry_run]
25
- version = repo.latest_version
26
- if repo.has_versions? && repo.current_ref != version
27
- output "Bumping version into #{version}"
28
- display_name = "#{repo_name}\##{version}"
29
- repo.checkout version
30
- core.repo_manager.update repo_name, version, repo, options
31
- end
32
- core.repo_manager.cache_installing_repo repo
21
+ # Update all installed repositories
22
+ # $ sspm update
23
+ def update_all_repositories(options = {})
24
+ core.repo_manager.each_repo do |repo|
25
+ update_repository repo.name, options
33
26
  end
27
+ end
34
28
 
35
- output "Success #{display_name}"
29
+ def update_repository_for_each_minor_version(driver, repo, options)
30
+ repo.package_minor_versions.any? do |minor_version|
31
+ latest_version = driver.latest_version(minor_version)
32
+ next false if core.repo_manager.exists?(repo.name, latest_version)
36
33
 
37
- # update deps
38
- if core.repo_manager.has_deps?(repo_name)
39
- output "Updating #{display_name}'s dependencies"
40
- deps = core.repo_manager.deps(repo_name)
41
- install_missing_dependencies deps, options
42
- output "Finish updating #{display_name}'s dependencies"
34
+ output "Updating #{repo.name}##{minor_version}.x"
35
+ package = create_new_version_package(driver, latest_version)
36
+ output "Success #{package.display_name}"
37
+
38
+ if package.has_dependencies?
39
+ output "Updating #{package.display_name}'s dependencies"
40
+ install_missing_dependencies package.dependencies, options
41
+ output "Finish updating #{package.display_name}'s dependencies"
42
+ end
43
+
44
+ true
43
45
  end
44
46
  end
45
47
 
46
- # Update all installed repositories
47
- # $ sspm update
48
- def update_all_repositories(options = {})
49
- core.repo_manager.each_installed_repo do |repo_name|
50
- update_repository repo_name, options
51
- end
48
+ def create_new_version_package(driver, new_version)
49
+ output "Bumping version into #{new_version}"
50
+ core.repo_manager.create_package driver, new_version
52
51
  end
53
52
 
54
53
  end
@@ -39,24 +39,24 @@ EOF
39
39
  def install_by_snippet_json
40
40
  snippet_json = ::JSON.parse(File.read("snippet.json"))
41
41
  snippet_json["dependencies"].each do |name, ref|
42
- core.api.install_repository_by_name name, ref, options
42
+ url = core.api.resolve_name_by_registry(name)
43
+ core.api.install_repository url, ref, options
43
44
  end
44
45
  end
45
46
 
46
47
  def install_by_names
47
48
  while has_next_token?
48
49
  token_str = next_token
50
+ repo_info = parse_repo_token(token_str)
49
51
  if is_name?(token_str)
50
- repo_info = parse_repo_token(token_str)
51
- core.api.install_repository_by_name repo_info[:name], repo_info[:ref], options
52
+ url = core.api.resolve_name_by_registry(repo_info[:name])
53
+ core.api.install_repository url, repo_info[:ref], options
52
54
  elsif is_url?(token_str)
53
- repo_info = parse_repo_token(token_str)
54
55
  repo_url = repo_info[:name]
55
- core.api.install_repository_by_url repo_url, repo_info[:ref], options
56
+ core.api.install_repository repo_url, repo_info[:ref], options
56
57
  elsif is_path?(token_str)
57
- repo_info = parse_repo_token(token_str)
58
58
  repo_path = repo_info[:name]
59
- core.api.install_repository_by_path repo_path, repo_info[:ref], options
59
+ core.api.install_repository repo_path, repo_info[:ref], options
60
60
  end
61
61
  end
62
62
  end
@@ -30,7 +30,7 @@ class SocialSnippet::Config
30
30
  resolve_home
31
31
 
32
32
  # env vars > args > config.json
33
- init_directories
33
+ init_filesystem
34
34
  load_file
35
35
  load_options options
36
36
  load_environment_variables
@@ -72,12 +72,12 @@ class SocialSnippet::Config
72
72
 
73
73
  def save_file
74
74
  @fields ||= {}
75
- ::File.write file_path, fields.to_json
75
+ core.storage.write file_path, fields.to_json
76
76
  end
77
77
 
78
78
  def load_file
79
79
  begin
80
- @fields = ::JSON.parse(::File.read file_path)
80
+ @fields = ::JSON.parse(core.storage.read file_path)
81
81
  rescue ::JSON::ParserError
82
82
  raise "error on parsing #{file_path}"
83
83
  end
@@ -88,6 +88,16 @@ class SocialSnippet::Config
88
88
  # config helpers
89
89
  #
90
90
 
91
+ def document_path
92
+ ::File.join home, "documents.yml"
93
+ end
94
+
95
+ def package_path(repo_name, rev_hash, path = nil)
96
+ path = "" if path.nil?
97
+ raise "ERROR" if rev_hash.nil?
98
+ ::File.join home, "packages", repo_name, rev_hash, path
99
+ end
100
+
91
101
  def file_path
92
102
  ::File.join home, "config.json"
93
103
  end
@@ -112,11 +122,11 @@ class SocialSnippet::Config
112
122
  get :debug
113
123
  end
114
124
 
115
- def init_directories
116
- ::FileUtils.mkdir_p home
117
- ::FileUtils.mkdir_p install_path
118
- ::FileUtils.mkdir_p repository_cache_path
119
- ::File.write file_path, {}.to_json unless ::File.exists?(file_path)
125
+ def init_filesystem
126
+ core.storage.mkdir_p home
127
+ core.storage.mkdir_p install_path
128
+ core.storage.mkdir_p repository_cache_path
129
+ core.storage.write file_path, {}.to_json unless core.storage.exists?(file_path)
120
130
  end
121
131
 
122
132
  private