vendorise 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e5cae912a9bd5f013c43802064dabca1f78cb0f
4
- data.tar.gz: b26e429ca1191a918db36407ec765eb1e72779ac
3
+ metadata.gz: 71fc0702ccecbcf00c3ac4fe2f66dfe8f405129c
4
+ data.tar.gz: 906e46e59a64be9defc2857adba66e40fd58e6b2
5
5
  SHA512:
6
- metadata.gz: 1728664bc30325c19ddb74ae8a890187d888ebc2f3b94a5c120f8731f225aa314aecf041926750aadb7ad4f72cca684587916025cd0541adf8e3a445953f90b5
7
- data.tar.gz: 6ee71f91f8c51043cac76db62d12d183c277c8be93acb3180d19bc6f01642790904e58d47027b51b24aa6990e1a5c95dac05b03959eb2a2f5303eabf7984bdf1
6
+ metadata.gz: 8a230aee1a198f2c322440afc3af3c349d3634910b683845e71d59cb7f28d490ae497d4527c7a5924d0da117339ec46ee1b145e9b80e4a859c5cc2cc59facd50
7
+ data.tar.gz: c12576e097bddb15168f026a7fb8aeecd52c51995808bb63c9fd0a0c35976b74e97964be7c08be5e430aeaddb44aa867ced7d3f7b4c7a32ec4f0958ab0a5a9f9
@@ -0,0 +1,19 @@
1
+ module Vendorise
2
+ class Arborist
3
+ attr_reader :path, :url
4
+
5
+ def initialize(path, url)
6
+ @path = path
7
+ @url = url
8
+ end
9
+
10
+ def subtree_already_exists?
11
+ Dir.exist?(path)
12
+ end
13
+
14
+ def subtree_command
15
+ cmd = subtree_already_exists? ? "pull" : "add"
16
+ "git subtree #{cmd} --prefix #{path} #{url} master --squash"
17
+ end
18
+ end
19
+ end
@@ -1,15 +1,17 @@
1
1
  module Vendorise
2
2
  class Parser
3
+ attr_reader :url
3
4
 
4
- class << self
5
- def gem_url(url)
6
- url =~ /^\s+$/ ? nil : url
7
- end
5
+ def initialize(url)
6
+ @url = url
7
+ end
8
8
 
9
- def gem_name(url)
10
- File.basename url, ".git"
11
- end
9
+ def gem_url
10
+ url =~ /^\s+$/ ? nil : url
12
11
  end
13
12
 
13
+ def gem_name
14
+ File.basename url, ".git"
15
+ end
14
16
  end
15
17
  end
@@ -1,13 +1,15 @@
1
1
  require "rake"
2
2
  require_relative "parser"
3
+ require_relative "arborist"
3
4
 
4
5
  namespace :vendorise do
5
6
  desc "Installs a gem from the specified url to /vendor/gems"
6
7
  task :gem, :url do |t, args|
7
- url = Vendorise::Parser.gem_url(args[:url]) or raise "Please specify a valid url for the gem"
8
- path = "vendor/gems/#{Vendorise::Parser.gem_name(args[:url])}"
9
- cmd = Dir.exist?(path) ? "pull" : "add"
8
+ parser = Vendorise::Parser.new(args[:url])
9
+ url = parser.gem_url or raise "Please specify a valid url for the gem"
10
10
 
11
- system("git subtree #{cmd} --prefix #{path} #{url} master --squash")
11
+ command = Vendorise::Arborist.new("vendor/gems/#{parser.gem_name}", url).subtree_command
12
+
13
+ system(command)
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module Vendorise
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,26 @@
1
+ require_relative "../../spec_helper"
2
+ require_relative "../../../lib/vendorise/arborist"
3
+
4
+ module Vendorise
5
+ describe Arborist do
6
+ describe :subtree_command do
7
+ subject { Arborist.new "foo/bar", "git@github.com:New-Bamboo/vendorise.git" }
8
+
9
+ context "when #subtree_already_exists? is false" do
10
+ before { allow(subject).to receive(:subtree_already_exists?).and_return(false) }
11
+
12
+ it "is git subtree add" do
13
+ expect(subject.subtree_command).to eq "git subtree add --prefix foo/bar git@github.com:New-Bamboo/vendorise.git master --squash"
14
+ end
15
+ end
16
+
17
+ context "when #subtree_already_exists? is true" do
18
+ before { allow(subject).to receive(:subtree_already_exists?).and_return(true) }
19
+
20
+ it "is git subtree pull" do
21
+ expect(subject.subtree_command).to eq "git subtree pull --prefix foo/bar git@github.com:New-Bamboo/vendorise.git master --squash"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,33 +1,33 @@
1
- require_relative "../../spec_helper.rb"
1
+ require_relative "../../spec_helper"
2
2
  require_relative "../../../lib/vendorise/parser"
3
3
 
4
4
  module Vendorise
5
5
  describe Parser do
6
6
  describe :gem_url do
7
7
  it "is nil for pure whitespace urls" do
8
- expect(Vendorise::Parser.gem_url(" ")).to eq nil
8
+ expect(Parser.new(" ").gem_url).to eq nil
9
9
  end
10
10
 
11
11
  it "is nil for nil urls" do
12
- expect(Vendorise::Parser.gem_url(nil)).to eq nil
12
+ expect(Parser.new(nil).gem_url).to eq nil
13
13
  end
14
14
 
15
15
  it "is a http url for a http url" do
16
- expect(Vendorise::Parser.gem_url("https://github.com/New-Bamboo/vendorise.git")).to eq "https://github.com/New-Bamboo/vendorise.git"
16
+ expect(Parser.new("https://github.com/New-Bamboo/vendorise.git").gem_url).to eq "https://github.com/New-Bamboo/vendorise.git"
17
17
  end
18
18
 
19
19
  it "is a ssh url for a ssh url" do
20
- expect(Vendorise::Parser.gem_url("git@github.com:New-Bamboo/vendorise.git")).to eq "git@github.com:New-Bamboo/vendorise.git"
20
+ expect(Parser.new("git@github.com:New-Bamboo/vendorise.git").gem_url).to eq "git@github.com:New-Bamboo/vendorise.git"
21
21
  end
22
22
  end
23
23
 
24
24
  describe :gem_name do
25
25
  it "is the last part of the path for a http url" do
26
- expect(Vendorise::Parser.gem_name("https://github.com/New-Bamboo/vendorise.git")).to eq "vendorise"
26
+ expect(Parser.new("https://github.com/New-Bamboo/vendorise.git").gem_name).to eq "vendorise"
27
27
  end
28
28
 
29
29
  it "is the last part of the path for a ssh url" do
30
- expect(Vendorise::Parser.gem_name("git@github.com:New-Bamboo/vendorise.git")).to eq "vendorise"
30
+ expect(Parser.new("git@github.com:New-Bamboo/vendorise.git").gem_name).to eq "vendorise"
31
31
  end
32
32
  end
33
33
  end
@@ -12,5 +12,15 @@ module Vendorise
12
12
  it "accepts a url argument" do
13
13
  expect(task.arg_names).to match_array [:url]
14
14
  end
15
+
16
+ it "creates a new arborist and passes it's command to system" do
17
+ fake_arborist = double("Arborist", subtree_command: "touch foo.tmp")
18
+ allow(Vendorise::Arborist).to receive(:new).with("vendor/gems/vendorise", "git@github.com:New-Bamboo/vendorise.git").and_return(fake_arborist)
19
+
20
+ task.invoke("git@github.com:New-Bamboo/vendorise.git")
21
+
22
+ expect(File.exist?("foo.tmp")).to be true
23
+ File.delete("foo.tmp")
24
+ end
15
25
  end
16
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vendorise
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
  - Iain Beeston
@@ -66,9 +66,11 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/vendorise.rb
69
+ - lib/vendorise/arborist.rb
69
70
  - lib/vendorise/parser.rb
70
71
  - lib/vendorise/tasks.rb
71
72
  - lib/vendorise/version.rb
73
+ - spec/lib/vendorise/arborist_spec.rb
72
74
  - spec/lib/vendorise/parser_spec.rb
73
75
  - spec/lib/vendorise/tasks_spec.rb
74
76
  - spec/spec_helper.rb
@@ -98,6 +100,7 @@ signing_key:
98
100
  specification_version: 4
99
101
  summary: Uses git subtree to download the source for a gem into /vendor/gems
100
102
  test_files:
103
+ - spec/lib/vendorise/arborist_spec.rb
101
104
  - spec/lib/vendorise/parser_spec.rb
102
105
  - spec/lib/vendorise/tasks_spec.rb
103
106
  - spec/spec_helper.rb