velcro 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/velcro ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
5
+ require 'velcro/executable'
6
+
7
+ Velcro::Executable.start
@@ -1,14 +1,12 @@
1
+ require 'velcro/errors'
2
+ require 'velcro/file_helpers'
1
3
  require 'ostruct'
2
4
 
3
5
  class Velcro
4
6
  class Brewfile
5
- DEPENDENCY_FORMAT = %r{^brew '(?<name>\S*)'(, '(?<version>\S*)')?$}
6
-
7
- attr_accessor :path
7
+ include FileHelpers
8
8
 
9
- def initialize(path)
10
- self.path = path
11
- end
9
+ DEPENDENCY_FORMAT = %r{^brew '(?<name>\S*)'(, '(?<version>\S*)')?$}
12
10
 
13
11
  def dependencies
14
12
  parse_dependencies(content)
@@ -29,7 +27,15 @@ class Velcro
29
27
  end
30
28
 
31
29
  def content
32
- File.read(self.path)
30
+ if location
31
+ File.read(brewfile_in(location))
32
+ else
33
+ fail BrewfileNotFound, 'Could not locate Brewfile'
34
+ end
35
+ end
36
+
37
+ def brewfile_in(directory)
38
+ File.join(directory, 'Brewfile')
33
39
  end
34
40
  end
35
41
  end
@@ -0,0 +1,3 @@
1
+ class Velcro
2
+ class BrewfileNotFound < StandardError; end
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'velcro'
2
+ require 'thor'
3
+
4
+ class Velcro
5
+ class Executable < Thor
6
+ default_task :install
7
+
8
+ desc 'install', 'Install dependencies defined in the Brewfile'
9
+ def install
10
+ velcro.install
11
+ end
12
+
13
+ no_tasks do
14
+ def velcro
15
+ Velcro.new
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class Velcro
2
+ module FileHelpers
3
+ def location
4
+ ENV['VELCRO_BREWFILE'] || recursive_search
5
+ end
6
+
7
+ def recursive_search(directory = Dir.pwd)
8
+ until directory == '/'
9
+ return directory if File.exists?(brewfile_in(directory))
10
+ directory = File.expand_path(File.join(directory, '..'))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,22 +1,29 @@
1
+ require 'velcro/file_helpers'
1
2
  require 'velcro/homebrew'
2
3
 
3
4
  class Velcro
4
5
  class Lockfile
5
- attr_accessor :path, :homebrew
6
+ include FileHelpers
6
7
 
7
- def initialize(path)
8
- self.path = path
8
+ attr_accessor :homebrew
9
+
10
+ def initialize
9
11
  self.homebrew = Homebrew.new
10
12
  end
11
13
 
12
14
  def generate(dependencies)
13
- [
14
- 'FORMULA',
15
- indent(generate_formula(dependencies)),
16
- '',
17
- 'DEPENDENCIES',
18
- indent(generate_dependencies(dependencies))
19
- ].flatten.join("\n")
15
+ File.open(lockfile_in(Dir.pwd), 'w+') do |lockfile|
16
+ lockfile.write(
17
+ [
18
+ 'FORMULA',
19
+ indent(generate_formula(dependencies)),
20
+ '',
21
+ 'DEPENDENCIES',
22
+ indent(generate_dependencies(dependencies)),
23
+ ''
24
+ ].flatten.join("\n")
25
+ )
26
+ end
20
27
  end
21
28
 
22
29
  def generate_formula(dependencies)
@@ -51,5 +58,9 @@ class Velcro
51
58
  " #{line}"
52
59
  end
53
60
  end
61
+
62
+ def lockfile_in(directory)
63
+ File.join(directory, 'Brewfile.lock')
64
+ end
54
65
  end
55
66
  end
@@ -1,3 +1,3 @@
1
1
  class Velcro
2
- VERSION = '0.0.1'
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/velcro.rb CHANGED
@@ -6,10 +6,10 @@ require 'velcro/lockfile'
6
6
  class Velcro
7
7
  attr_accessor :homebrew, :brewfile, :lockfile
8
8
 
9
- def initialize(path)
9
+ def initialize
10
10
  self.homebrew = Homebrew.new
11
- self.brewfile = Brewfile.new(path)
12
- self.lockfile = Lockfile.new(path)
11
+ self.brewfile = Brewfile.new
12
+ self.lockfile = Lockfile.new
13
13
  end
14
14
 
15
15
  def install
@@ -22,7 +22,7 @@ describe Velcro::Brewfile do
22
22
  ]
23
23
  }
24
24
 
25
- subject { described_class.new(file.path) }
25
+ subject { described_class.new }
26
26
 
27
27
  describe '#parse' do
28
28
  it 'parses the Brewfile' do
@@ -0,0 +1,21 @@
1
+ require 'velcro/file_helpers'
2
+
3
+ describe Velcro::FileHelpers do
4
+ subject { Class.new.extend(described_class) }
5
+
6
+ describe '#location' do
7
+ let(:velcro_brewfile) { stub }
8
+
9
+ it 'returns the brewfile location specified in the environment variable' do
10
+ ENV.stub(:[]).with('VELCRO_BREWFILE') { velcro_brewfile }
11
+ subject.location.should == velcro_brewfile
12
+ end
13
+
14
+ it 'recursively searches for the Brewfile if not specified' do
15
+ subject.stub(:recursive_search) { nil }
16
+ subject.should_receive(:recursive_search)
17
+
18
+ subject.location
19
+ end
20
+ end
21
+ end
@@ -1,28 +1,30 @@
1
1
  require 'velcro/lockfile'
2
+ require 'tempfile'
2
3
 
3
4
  describe Velcro::Lockfile do
4
- subject { described_class.new(stub) }
5
+ subject { described_class.new }
5
6
 
6
7
  let(:postgresql) { OpenStruct.new(name: 'postgresql', version: nil) }
7
- let(:redis) { OpenStruct.new(name: 'redis', version: '2.4.16') }
8
+ let(:redis) { OpenStruct.new(name: 'redis', version: '2.4.16') }
9
+ let(:ossp_uuid) { OpenStruct.new(name: 'ossp-uuid', version: '1.6.2') }
10
+ let(:readline) { OpenStruct.new(name: 'readline', version: '6.2.4') }
11
+
8
12
  let(:dependencies) { [postgresql, redis] }
13
+ let(:child_dependencies) { [ossp_uuid, readline] }
14
+
15
+ let(:lockfile) { Tempfile.new('lockfile') }
9
16
 
10
17
  before do
11
- subject.homebrew.stub(:shellout) { nil }
12
- subject.homebrew.stub(:child_dependencies).with(postgresql) {
13
- [
14
- OpenStruct.new(name: 'ossp-uuid', version: '1.6.2'),
15
- OpenStruct.new(name: 'readline', version: '6.2.4')
16
- ]
17
- }
18
+ subject.homebrew.stub(:child_dependencies).with(postgresql) { child_dependencies }
18
19
  subject.homebrew.stub(:child_dependencies).with(redis) { [] }
19
20
  subject.homebrew.stub(:versions).with(postgresql) { '9.1.4' }
20
- subject.homebrew.stub(:versions).with(redis) { '2.4.16' }
21
+ subject.stub(:lockfile_in) { lockfile }
21
22
  end
22
23
 
23
24
  describe '#generate' do
24
25
  it 'creates a Brewfile.lock for the installed dependencies' do
25
- subject.generate(dependencies).should == <<-END.gsub(/^ {8}/, '').rstrip
26
+ subject.generate(dependencies)
27
+ File.read(lockfile).should == <<-END.gsub(/^ {8}/, '')
26
28
  FORMULA
27
29
  postgresql (9.1.4)
28
30
  ossp-uuid (1.6.2)
data/spec/velcro_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'velcro'
2
2
 
3
3
  describe Velcro do
4
- subject { described_class.new(stub) }
4
+ subject { described_class.new }
5
5
 
6
6
  context '#install' do
7
7
  let(:homebrew) { stub(install_dependencies: nil) }
data/velcro.gemspec CHANGED
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = `git ls-files -- spec/*`.split
16
16
  gem.require_paths = ['lib']
17
17
 
18
+ gem.add_dependency 'thor' , '~> 0.16.0'
19
+
18
20
  gem.add_development_dependency 'rspec', '~> 2.11.0'
19
21
  gem.add_development_dependency 'pry'
20
22
  gem.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: velcro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,8 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-20 00:00:00.000000000 Z
13
+ date: 2012-08-21 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 0.16.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.16.0
15
31
  - !ruby/object:Gem::Dependency
16
32
  name: rspec
17
33
  requirement: !ruby/object:Gem::Requirement
@@ -64,7 +80,8 @@ description: Manage your dependencies with homebrew like you manage your gems wi
64
80
  bundler
65
81
  email:
66
82
  - vanstee@highgroove.com
67
- executables: []
83
+ executables:
84
+ - velcro
68
85
  extensions: []
69
86
  extra_rdoc_files: []
70
87
  files:
@@ -75,12 +92,17 @@ files:
75
92
  - LICENSE.txt
76
93
  - README.md
77
94
  - Rakefile
95
+ - bin/velcro
78
96
  - lib/velcro.rb
79
97
  - lib/velcro/brewfile.rb
98
+ - lib/velcro/errors.rb
99
+ - lib/velcro/executable.rb
100
+ - lib/velcro/file_helpers.rb
80
101
  - lib/velcro/homebrew.rb
81
102
  - lib/velcro/lockfile.rb
82
103
  - lib/velcro/version.rb
83
104
  - spec/velcro/brewfile_spec.rb
105
+ - spec/velcro/file_helpers_spec.rb
84
106
  - spec/velcro/homebrew_spec.rb
85
107
  - spec/velcro/lockfile_spec.rb
86
108
  - spec/velcro_spec.rb
@@ -99,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
121
  version: '0'
100
122
  segments:
101
123
  - 0
102
- hash: -1769184219394736127
124
+ hash: 555263360612235969
103
125
  required_rubygems_version: !ruby/object:Gem::Requirement
104
126
  none: false
105
127
  requirements:
@@ -108,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
130
  version: '0'
109
131
  segments:
110
132
  - 0
111
- hash: -1769184219394736127
133
+ hash: 555263360612235969
112
134
  requirements: []
113
135
  rubyforge_project:
114
136
  rubygems_version: 1.8.23
@@ -117,6 +139,7 @@ specification_version: 3
117
139
  summary: Manage your dependencies with homebrew like you manage your gems with bundler
118
140
  test_files:
119
141
  - spec/velcro/brewfile_spec.rb
142
+ - spec/velcro/file_helpers_spec.rb
120
143
  - spec/velcro/homebrew_spec.rb
121
144
  - spec/velcro/lockfile_spec.rb
122
145
  - spec/velcro_spec.rb