torba 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8077046fe1ce43eba5020e6c3bf29c60ddbb5e78
4
- data.tar.gz: bd3ebc23042ec750e0b7079b89b4b5cc5bc05886
3
+ metadata.gz: ce67e52a36d478eab2dc503c588b99ff40221fd0
4
+ data.tar.gz: 9133124e1d23f67c688fddd7d8d58bcaaf68b54a
5
5
  SHA512:
6
- metadata.gz: 2466b9ec97f44de5aec27493474978ec031679f1d6527b1365dbae4335a7725ccaf7acf4ff3a83c8e89b567b05c099d6210b0b3cded8710a123ae622e9f42c47
7
- data.tar.gz: 19cb9f0cc57317562981ce3e795b0615a1082ad098ce4e5bb242ba7b253fcff14b05dda659282b81f07c68679c00bbcac1af26dfa55a17528d03c99092f23f83
6
+ metadata.gz: da460e539b47b1e584543a3449e17acac02ae6dcf32d8c8a18bf0bfd8bed9d9e569b63fbcedbf4a5086b18deaffe5e57898b7049ad6070da41f1c23b15d54b7b
7
+ data.tar.gz: 4936ecdb12589165bb49a6553f99434833eb2b97595e3dd75fbbd86c888fbd2e5b98175d61f38ad49b750350be1e86eff3876c03e6dfed4f1b79a7108be12590
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  ## Unreleased
2
2
 
3
+ ## Version 0.2.0
4
+
5
+ ### Enhancements
6
+
7
+ * Name for GH releases can be optional
8
+ * Cached zip remote contains URL filename in path for better introspection
9
+ * GithubRelease remote: introduce #repository_user, #repository_name
10
+
11
+ ### Bug fixes
12
+
13
+ * Display actual exception (if any) instead of SystemExitError for pow
14
+ * Remote source always returns absolute path even if Torba.home_path/cache_path
15
+ is relative to current directory
16
+
3
17
  ## Version 0.1.1
4
18
 
5
19
  ### Bug fixes
data/Readme.md CHANGED
@@ -129,6 +129,12 @@ i.e. with "v" prefix if present), more on "import" below. For example,
129
129
  gh_release "scroll_magic", source: "janpaepke/ScrollMagic", tag: "v.2.0.0"
130
130
  ```
131
131
 
132
+ You can omit the name, it will be equal to the repository name:
133
+
134
+ ```
135
+ gh_release source: "janpaepke/ScrollMagic", tag: "v.2.0.0" # "ScrollMagic" is assumed
136
+ ```
137
+
132
138
  ### "Packing the torba" process
133
139
 
134
140
  When you run `torba pack` the following happens:
@@ -37,10 +37,16 @@ module Torba
37
37
  end
38
38
 
39
39
  # Adds {Package} with {RemoteSources::GithubRelease} to {#packages}
40
- def gh_release(name, options = {})
40
+ def gh_release(name = nil, options = {})
41
+ if name.is_a?(Hash)
42
+ options, name = name, nil
43
+ end
44
+
41
45
  source = options.fetch(:source)
42
46
  tag = options.fetch(:tag)
43
47
  remote_source = RemoteSources::GithubRelease.new(source, tag)
48
+
49
+ name ||= remote_source.repository_name
44
50
  packages << Package.new(name, remote_source, options)
45
51
  end
46
52
 
@@ -11,10 +11,12 @@ module Torba
11
11
  ensure_cached
12
12
 
13
13
  Dir.glob(File.join(cache_path, pattern)).reject{ |path| File.directory?(path) }.map do |path|
14
- [path, path.sub(/#{cache_path}\/?/, "")]
14
+ [File.absolute_path(path), path.sub(/#{cache_path}\/?/, "")]
15
15
  end
16
16
  end
17
17
 
18
+ # @return [String] unique short name used as a representation of the remote source.
19
+ # Used by default as a cache folder name.
18
20
  def digest
19
21
  raise NotImplementedError
20
22
  end
@@ -22,7 +24,7 @@ module Torba
22
24
  private
23
25
 
24
26
  def cache_path
25
- raise NotImplementedError
27
+ @cache_path ||= File.join(Torba.cache_path, digest)
26
28
  end
27
29
 
28
30
  def ensure_cached
@@ -7,8 +7,18 @@ module Torba
7
7
  # @return [String] repository user and name.
8
8
  # @example
9
9
  # "jashkenas/underscore"
10
+ # @see #repository_name
11
+ # @see #repository_user
10
12
  attr_reader :source
11
13
 
14
+ # @return [String]
15
+ # @since 0.2.0
16
+ attr_reader :repository_name
17
+
18
+ # @return [String]
19
+ # @since 0.2.0
20
+ attr_reader :repository_user
21
+
12
22
  # @return [String] repository tag.
13
23
  # @example
14
24
  # "v1.8.3"
@@ -19,6 +29,7 @@ module Torba
19
29
  def initialize(source, tag)
20
30
  @source = source
21
31
  @tag = tag
32
+ @repository_user, @repository_name = source.split("/")
22
33
  super("https://github.com/#{source}/archive/#{tag}.zip")
23
34
  end
24
35
  end
@@ -13,22 +13,15 @@ module Torba
13
13
  class Zip
14
14
  include Common
15
15
 
16
- attr_reader :url
16
+ attr_reader :url, :digest
17
17
 
18
18
  def initialize(url)
19
19
  @url = url
20
- end
21
-
22
- def digest
23
- Torba.digest(url)
20
+ @digest = "#{File.basename url, '.zip'}-#{Torba.digest(url)}"
24
21
  end
25
22
 
26
23
  private
27
24
 
28
- def cache_path
29
- @cache_path ||= File.join(Torba.cache_path, digest)
30
- end
31
-
32
25
  def ensure_cached
33
26
  unless Dir.exist?(cache_path)
34
27
  FileUtils.mkdir_p(cache_path)
data/lib/torba/verify.rb CHANGED
@@ -1,2 +1,7 @@
1
1
  require "torba"
2
- Torba.pretty_errors { Torba.verify }
2
+
3
+ if STDOUT.tty?
4
+ Torba.pretty_errors { Torba.verify }
5
+ else
6
+ Torba.verify
7
+ end
data/test/Torbafile CHANGED
@@ -1,3 +1,5 @@
1
+ zip "trumbowyg-from-zip", url: "https://github.com/torba-rb/Trumbowyg/archive/1.1.6.zip", import: ["dist/trumbowyg.js"]
2
+
1
3
  gh_release "trumbowyg", source: "torba-rb/Trumbowyg", tag: "1.1.7", import: %w[
2
4
  dist/trumbowyg.js
3
5
  dist/ui/*.css
@@ -6,19 +6,36 @@ module Torba
6
6
  @manifest ||= Manifest.build("test/Torbafile")
7
7
  end
8
8
 
9
+ def find(file_path)
10
+ manifest.load_path.map{ |lp| File.join(lp, file_path) }.find{ |full_path| File.exists?(full_path) }
11
+ end
12
+
9
13
  def assert_exists(file_path)
10
- super File.join(manifest.load_path, file_path)
14
+ assert find(file_path)
15
+ end
16
+
17
+ def refute_exists(file_path)
18
+ refute find(file_path)
19
+ end
20
+
21
+ def read(file_path)
22
+ File.read(find(file_path))
11
23
  end
12
24
 
13
25
  def test_pack
14
26
  manifest.pack
15
27
 
28
+ assert_exists "trumbowyg-from-zip/trumbowyg.js"
29
+ refute_exists "trumbowyg-from-zip/trumbowyg.css.erb"
30
+ refute_exists "trumbowyg-from-zip/icons.png"
31
+ refute_exists "trumbowyg-from-zip/icons-2x.png"
32
+
16
33
  assert_exists "trumbowyg/trumbowyg.js"
17
34
  assert_exists "trumbowyg/trumbowyg.css.erb"
18
35
  assert_exists "trumbowyg/icons.png"
19
36
  assert_exists "trumbowyg/icons-2x.png"
20
37
 
21
- css = File.read File.join(manifest.load_path, "trumbowyg/trumbowyg.css.erb")
38
+ css = read "trumbowyg/trumbowyg.css.erb"
22
39
  assert_includes css, "background: transparent url('<%= asset_path('trumbowyg/icons.png') %>') no-repeat;"
23
40
  assert_includes css, "background-image: url('<%= asset_path('trumbowyg/icons-2x.png') %>')"
24
41
  end
@@ -6,15 +6,19 @@ module Torba
6
6
  @manifest ||= Manifest.new
7
7
  end
8
8
 
9
+ def package
10
+ manifest.packages.first
11
+ end
12
+
13
+ def remote
14
+ package.remote_source
15
+ end
16
+
9
17
  def test_zip
10
18
  manifest.zip "angular", url: "http://angularjs.com/angularjs.zip"
11
19
 
12
20
  assert_equal 1, manifest.packages.size
13
-
14
- package = manifest.packages.first
15
21
  assert_equal "angular", package.name
16
-
17
- remote = package.remote_source
18
22
  assert_instance_of RemoteSources::Zip, remote
19
23
  assert_equal "http://angularjs.com/angularjs.zip", remote.url
20
24
  end
@@ -26,19 +30,20 @@ module Torba
26
30
  end
27
31
 
28
32
  def test_gh_release
29
- manifest.gh_release "underscore", source: "jashkenas/underscore", tag: "1.8.3"
33
+ manifest.gh_release "lo-dash", source: "jashkenas/underscore", tag: "1.8.3"
30
34
 
31
35
  assert_equal 1, manifest.packages.size
32
-
33
- package = manifest.packages.first
34
- assert_equal "underscore", package.name
35
-
36
- remote = package.remote_source
36
+ assert_equal "lo-dash", package.name
37
37
  assert_instance_of RemoteSources::GithubRelease, remote
38
38
  assert_equal "jashkenas/underscore", remote.source
39
39
  assert_equal "1.8.3", remote.tag
40
40
  end
41
41
 
42
+ def test_gh_release_implicit_name
43
+ manifest.gh_release source: "jashkenas/underscore", tag: "1.8.3"
44
+ assert_equal "underscore", package.name
45
+ end
46
+
42
47
  def test_gh_release_wo_source
43
48
  assert_raises(KeyError) do
44
49
  manifest.gh_release "underscore", tag: "1.8.3"
@@ -1,37 +1,17 @@
1
1
  require "test_helper"
2
- require "fileutils"
3
- require "torba/remote_sources/common"
4
2
 
5
3
  module Torba
6
4
  class PackageImportListTest < Minitest::Test
7
5
  def source_dir
8
- @source_dir ||= begin
9
- dir = File.join(Torba.home_path, "source")
10
- FileUtils.mkdir_p(dir)
11
- dir
12
- end
6
+ @source_dir ||= File.join(Torba.home_path, "source")
13
7
  end
14
8
 
15
9
  def touch(path)
16
- absolute_path = File.join(source_dir, path)
17
- FileUtils.mkdir_p(File.dirname(absolute_path))
18
- FileUtils.touch(absolute_path)
19
- end
20
-
21
- class RemoteSource
22
- include RemoteSources::Common
23
-
24
- attr_reader :cache_path
25
-
26
- def initialize(cache_path)
27
- @cache_path = cache_path
28
- end
29
-
30
- def ensure_cached; end
10
+ super File.join(source_dir, path)
31
11
  end
32
12
 
33
13
  def remote_source
34
- @remote_source ||= RemoteSource.new(source_dir)
14
+ @remote_source ||= Test::RemoteSource.new(source_dir)
35
15
  end
36
16
 
37
17
  def test_single_file_path
@@ -0,0 +1,62 @@
1
+ require "test_helper"
2
+ require "fileutils"
3
+
4
+ module Torba
5
+ class CommonRemoteSourceTest < Minitest::Test
6
+ def cache_path
7
+ Torba.home_path
8
+ end
9
+
10
+ def remote
11
+ @remote ||= Test::RemoteSource.new(cache_path)
12
+ end
13
+
14
+ def touch(path)
15
+ super File.join(cache_path, path)
16
+ end
17
+
18
+ def assert_valid_tuple(path, tuple)
19
+ assert_equal File.join(cache_path, path), tuple[0]
20
+ assert_equal path, tuple[1]
21
+ end
22
+
23
+ def test_glob
24
+ touch "one.jpg"
25
+ touch "two.jpg"
26
+
27
+ tuples = remote["*"]
28
+ assert_equal 2, tuples.size
29
+
30
+ tuple1, tuple2 = tuples
31
+ assert_valid_tuple "one.jpg", tuple1
32
+ assert_valid_tuple "two.jpg", tuple2
33
+ end
34
+
35
+ def test_no_directories
36
+ touch "hello/one.jpg"
37
+
38
+ tuples = remote["*"]
39
+ assert_equal 0, remote["*"].size
40
+
41
+ tuples = remote["**/*"]
42
+ assert_equal 1, tuples.size
43
+
44
+ assert_valid_tuple "hello/one.jpg", tuples.first
45
+ end
46
+
47
+ def test_always_absolute_path
48
+ touch "hello/one.jpg"
49
+
50
+ Dir.chdir(cache_path) do
51
+ remote = Test::RemoteSource.new("./hello")
52
+
53
+ tuples = remote["*"]
54
+ assert_equal 1, tuples.size
55
+
56
+ tuple = tuples.first
57
+ assert_equal File.join(cache_path, "hello/one.jpg"), tuple[0]
58
+ assert_equal "one.jpg", tuple[1]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -3,11 +3,19 @@ require "test_helper"
3
3
  module Torba
4
4
  class GithubReleaseTest < Minitest::Test
5
5
  def remote
6
- RemoteSources::GithubRelease.new("repo/user", "v.2.0.0")
6
+ RemoteSources::GithubRelease.new("user/repo", "v.2.0.0")
7
7
  end
8
8
 
9
9
  def test_source
10
- assert_equal "repo/user", remote.source
10
+ assert_equal "user/repo", remote.source
11
+ end
12
+
13
+ def test_repository_name
14
+ assert_equal "repo", remote.repository_name
15
+ end
16
+
17
+ def test_repository_user
18
+ assert_equal "user", remote.repository_user
11
19
  end
12
20
 
13
21
  def test_tag
@@ -15,7 +23,7 @@ module Torba
15
23
  end
16
24
 
17
25
  def test_url
18
- assert_equal "https://github.com/repo/user/archive/v.2.0.0.zip", remote.url
26
+ assert_equal "https://github.com/user/repo/archive/v.2.0.0.zip", remote.url
19
27
  end
20
28
  end
21
29
  end
@@ -7,7 +7,7 @@ module Torba
7
7
  assert_equal "http://jquery.com/jquery.zip", remote.url
8
8
  end
9
9
 
10
- def test_digest
10
+ def test_unique_digest
11
11
  remote = RemoteSources::Zip.new("http://jquery.com/jquery.zip")
12
12
  same_remote = RemoteSources::Zip.new("http://jquery.com/jquery.zip")
13
13
 
@@ -18,6 +18,11 @@ module Torba
18
18
  refute_equal remote.digest, another_remote.digest
19
19
  end
20
20
 
21
+ def test_digest_contains_filename
22
+ remote = RemoteSources::Zip.new("http://jquery.com/jquery.zip")
23
+ assert_match /^jquery-/, remote.digest
24
+ end
25
+
21
26
  def test_404
22
27
  exception = assert_raises(Errors::ShellCommandFailed) do
23
28
  RemoteSources::Zip.new("http://jquery.com/jquery.zip")["*"]
data/test/test_helper.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require "bundler/setup"
2
2
  require "torba"
3
+ require "torba/remote_sources/common"
3
4
 
4
5
  require "minitest/autorun"
5
6
  require "tmpdir"
7
+ require "fileutils"
6
8
 
7
9
  module Torba
8
10
  module Test
9
11
  module TempHome
10
12
  def before_setup
11
- Torba.home_path = @_torba_tmp_dir = Dir.mktmpdir("torba")
13
+ Torba.home_path = @_torba_tmp_dir = File.realpath(Dir.mktmpdir("torba"))
12
14
  super
13
15
  end
14
16
 
@@ -28,10 +30,30 @@ module Torba
28
30
  refute File.exists?(file_path)
29
31
  end
30
32
  end
33
+
34
+ module Touch
35
+ def touch(path)
36
+ FileUtils.mkdir_p(File.dirname(path))
37
+ FileUtils.touch(path)
38
+ end
39
+ end
40
+
41
+ class RemoteSource
42
+ include RemoteSources::Common
43
+
44
+ attr_reader :cache_path
45
+
46
+ def initialize(cache_path)
47
+ @cache_path = cache_path
48
+ end
49
+
50
+ def ensure_cached; end
51
+ end
31
52
  end
32
53
  end
33
54
 
34
55
  class Minitest::Test
35
56
  include Torba::Test::TempHome
36
57
  include Torba::Test::AssertExists
58
+ include Torba::Test::Touch
37
59
  end
data/torba.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "torba"
3
- spec.version = "0.1.1"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Andrii Malyshko"]
5
5
  spec.email = ["mail@nashbridges.me"]
6
6
  spec.description = "Bundler for Sprockets"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Malyshko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-28 00:00:00.000000000 Z
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -102,6 +102,7 @@ files:
102
102
  - test/import_list_test.rb
103
103
  - test/manifest_test.rb
104
104
  - test/package/import_list_test.rb
105
+ - test/remote_sources/common_test.rb
105
106
  - test/remote_sources/github_release_test.rb
106
107
  - test/remote_sources/zip_test.rb
107
108
  - test/test_helper.rb
@@ -137,6 +138,7 @@ test_files:
137
138
  - test/import_list_test.rb
138
139
  - test/manifest_test.rb
139
140
  - test/package/import_list_test.rb
141
+ - test/remote_sources/common_test.rb
140
142
  - test/remote_sources/github_release_test.rb
141
143
  - test/remote_sources/zip_test.rb
142
144
  - test/test_helper.rb