gondler 0.1.3 → 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: 634edf93cbd25446d48e0b3398c216bc18bb70d0
4
- data.tar.gz: 16b89b6eca979a8da0cfaa94087b7e1d9ad168cd
3
+ metadata.gz: 9a4bbc74994c0cd4aeeba7733ca38b6682e97edb
4
+ data.tar.gz: dfb30ba73178a52fd6a6f98852db63a641e2074e
5
5
  SHA512:
6
- metadata.gz: ece921976ddad9d0c5a4838191779b07fbf69bd2e1e28dbc79af443e313329ceeaff132007a34472fd95228a96e914dedc0177bb656c2820e30e9478de15bfce
7
- data.tar.gz: 3dcf97bb1520f2bf2051b54835826c7f32ab388adde137cafc5f5ad59f9b203b38b643c2d7c906af3b20eef2503b6e692a477c51165aa6c4a7ae2e18ba6c5ee8
6
+ metadata.gz: 990993d6c905170bfee5aa5bf7fe32ff146e571effc4090fe3e7a30f7b4a3d1fd60427d94dfd67eb6f571e04b1fed8baa9f7a6f039f865b73781f7accaeea456
7
+ data.tar.gz: abaa9acd45bd9b22e279fff1045aea87dc95ee42e77617a7c9fa79752c3c81db43c4582256f1075d02c9235196faa2c607521517082530ffb6d9f6ccf0d37362
data/Gemfile CHANGED
@@ -4,6 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :development do
7
- gem 'rspec'
7
+ gem 'rspec', '2.14.1'
8
8
  gem 'pry'
9
9
  end
data/README.md CHANGED
@@ -24,6 +24,8 @@ bundler for golang. inspired by [gom](https://github.com/mattn/gom).
24
24
  like gom's Gomfile
25
25
 
26
26
  ```ruby
27
+ itself 'github.com/rosylilly/test'
28
+
27
29
  gom 'github.com/golang/glog'
28
30
  package 'github.com/golang/glog'
29
31
 
data/lib/gondler/cli.rb CHANGED
@@ -22,6 +22,8 @@ module Gondler
22
22
  package.resolve
23
23
  end
24
24
  end
25
+
26
+ gomfile.itself_package.get if gomfile.itself_package
25
27
  rescue Gondler::Package::InstallError => e
26
28
  puts e.message
27
29
  exit(1)
data/lib/gondler/env.rb CHANGED
@@ -2,6 +2,11 @@ module Gondler
2
2
  class Env
3
3
  class << self
4
4
  def accessor(name, source)
5
+ original_value = ENV[source.to_s]
6
+ define_method("orig_#{name}") do
7
+ original_value
8
+ end
9
+
5
10
  define_method(name) do
6
11
  @environments[source]
7
12
  end
@@ -5,12 +5,40 @@ module Gondler
5
5
  def initialize(path)
6
6
  raise NotFound, path unless File.exist?(path)
7
7
  @packages = []
8
+ @itself = nil
8
9
 
9
10
  load(path)
10
11
  end
11
12
  attr_reader :packages
12
13
 
14
+ def itself(name)
15
+ @itself = name
16
+ end
17
+
18
+ def itself_package
19
+ if !@itself && Gondler.env.orig_path
20
+ realpath = proc do |path|
21
+ if File.respond_to?(:realpath) # 1.9+
22
+ File.realpath(path)
23
+ else
24
+ path
25
+ end
26
+ end
27
+
28
+ orig_src = realpath[File.join(Gondler.env.orig_path, 'src')]
29
+ dir = realpath[File.dirname(@path)]
30
+ if dir.start_with?(orig_src)
31
+ @itself = dir[orig_src.size.succ .. -1]
32
+ end
33
+ end
34
+
35
+ if @itself
36
+ Gondler::Package.new(@itself, :path => '.')
37
+ end
38
+ end
39
+
13
40
  def load(path)
41
+ @path = File.expand_path(path)
14
42
  instance_eval(File.read(path))
15
43
  end
16
44
 
@@ -1,4 +1,5 @@
1
1
  require 'English'
2
+ require 'pathname'
2
3
 
3
4
  module Gondler
4
5
  class Package
@@ -14,8 +15,11 @@ module Gondler
14
15
  @group = options[:group]
15
16
  @fix = options[:fix] || false
16
17
  @flag = options[:flag]
18
+ @path = options[:path]
17
19
  end
18
20
 
21
+ attr_reader :name, :branch, :tag, :commit, :os, :group, :fix, :flag, :path
22
+
19
23
  def os
20
24
  case @os
21
25
  when String
@@ -56,19 +60,14 @@ module Gondler
56
60
  end
57
61
 
58
62
  def get
59
- args = %w(go get -d -u)
60
- args << '-fix' if @fix
61
- args << @name
62
-
63
- result = `#{args.join(' ')} 2>&1`
64
-
65
- unless $CHILD_STATUS.success?
66
- raise InstallError.new("#{@name} download error\n" + result)
63
+ if @path
64
+ get_by_path
65
+ else
66
+ get_by_package
67
67
  end
68
68
  end
69
69
 
70
70
  def checkout
71
- src_path = Pathname.new(Gondler.env.path) + 'src'
72
71
  @name.split('/').reduce(src_path) do |path, dir|
73
72
  path += dir
74
73
  if File.directory?(path + '.git')
@@ -107,5 +106,39 @@ module Gondler
107
106
  def to_s
108
107
  "#{@name}" + (target ? " (#{target})" : '')
109
108
  end
109
+
110
+ private
111
+
112
+ def env_path
113
+ Pathname.new(Gondler.env.path)
114
+ end
115
+
116
+ def src_path
117
+ env_path + 'src'
118
+ end
119
+
120
+ def get_by_path
121
+ target = src_path.join(@name)
122
+ FileUtils.mkdir_p(target.dirname)
123
+ FileUtils.remove_entry_secure(target) if target.exist?
124
+ if @path.to_s.start_with?('/') # absolute path
125
+ source = @path
126
+ else # relative path from Gomfile
127
+ source = env_path.dirname.join(@path).relative_path_from(target.dirname)
128
+ end
129
+ File.symlink(source, target)
130
+ end
131
+
132
+ def get_by_package
133
+ args = %w(go get -d -u)
134
+ args << '-fix' if @fix
135
+ args << @name
136
+
137
+ result = `#{args.join(' ')} 2>&1`
138
+
139
+ unless $CHILD_STATUS.success?
140
+ raise InstallError.new("#{@name} download error\n" + result)
141
+ end
142
+ end
110
143
  end
111
144
  end
@@ -1,3 +1,3 @@
1
1
  module Gondler
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,17 +1,28 @@
1
1
  require 'spec_helper'
2
- require 'tempfile'
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require 'pathname'
3
6
 
4
7
  describe Gondler::Gomfile do
5
- let(:gomfile) { described_class.new(path) }
6
- let(:file) do
7
- Tempfile.open('Gomfile').tap do|f|
8
- f.print(content)
9
- f.flush
10
- end
8
+ let(:tmpdir) { Dir.mktmpdir("gondler-gomfile-spec") }
9
+ after { FileUtils.remove_entry_secure(tmpdir) }
10
+
11
+ let(:package_dir) do
12
+ Pathname.new(tmpdir).join('src', 'example.com', 'test').tap(&:mkpath)
11
13
  end
12
- let(:path) { file.path }
14
+
15
+ let(:path) { package_dir.join('Gomfile') }
13
16
  let(:content) { '' }
14
- after { file.close! }
17
+
18
+ let(:gomfile) do
19
+ open(path, 'w') { |io| io.write content }
20
+ described_class.new(path)
21
+ end
22
+
23
+ before do
24
+ allow(Gondler.env).to receive(:orig_path) { tmpdir }
25
+ end
15
26
 
16
27
  describe '#initialize' do
17
28
  let(:path) { 'Gomfile' }
@@ -66,4 +77,24 @@ describe Gondler::Gomfile do
66
77
  expect(gomfile.packages.first.os).to eq(%w(darwin linux))
67
78
  end
68
79
  end
80
+
81
+ describe "#itself_package" do
82
+ subject(:package) { gomfile.itself_package }
83
+
84
+ it "returns package for Gomfile's repo" do
85
+ expect(package.name).to eq 'example.com/test'
86
+ expect(package.path).to eq '.'
87
+ end
88
+
89
+ context "with itself(...)" do
90
+ before do
91
+ gomfile.itself 'example.org/test2'
92
+ end
93
+
94
+ it "returns package for Gomfile's repo, but different dir" do
95
+ expect(package.name).to eq 'example.org/test2'
96
+ expect(package.path).to eq '.'
97
+ end
98
+ end
99
+ end
69
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gondler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Kusano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-17 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  requirements: []
90
90
  rubyforge_project:
91
- rubygems_version: 2.2.0
91
+ rubygems_version: 2.2.2
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: bundler for golang