berkshelf-shims 0.1.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.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .bin
20
+ vendor
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ ruby-1.9.2
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - "1.9.2"
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'rspec'
7
+ gem 'debugger', :platform => :ruby_19
8
+ gem 'simplecov'
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ berkshelf-shims (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ columnize (0.3.6)
10
+ debugger (1.5.0)
11
+ columnize (>= 0.3.1)
12
+ debugger-linecache (~> 1.2.0)
13
+ debugger-ruby_core_source (~> 1.2.0)
14
+ debugger-linecache (1.2.0)
15
+ debugger-ruby_core_source (1.2.0)
16
+ diff-lcs (1.1.3)
17
+ multi_json (1.6.1)
18
+ rake (10.0.3)
19
+ rspec (2.12.0)
20
+ rspec-core (~> 2.12.0)
21
+ rspec-expectations (~> 2.12.0)
22
+ rspec-mocks (~> 2.12.0)
23
+ rspec-core (2.12.2)
24
+ rspec-expectations (2.12.1)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.12.1)
27
+ simplecov (0.7.1)
28
+ multi_json (~> 1.0)
29
+ simplecov-html (~> 0.7.1)
30
+ simplecov-html (0.7.1)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ berkshelf-shims!
37
+ debugger
38
+ rake
39
+ rspec
40
+ simplecov
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ berkshelf-shims
2
+ ===============
3
+
4
+ Provide shims functionality for berkshelf.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :build => [:spec]
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'berkshelf-shims/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "berkshelf-shims"
8
+ gem.version = WP::Cookbook::VERSION
9
+ gem.authors = ["Jeff Bellegarde"]
10
+ gem.email = ["bellegar@gmail.com"]
11
+ gem.description = %q{Shim functionality for Berkshelf}
12
+ gem.summary = %q{Provides methods to create a cookbooks directory derived from Berksfile.lock.}
13
+ gem.homepage = "https://github.com/JeffBellegarde/berkshelf-shims"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ end
@@ -0,0 +1,5 @@
1
+ module WP
2
+ module Cookbook
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,60 @@
1
+ module BerkshelfShims
2
+
3
+ class UnknownCookbookReferenceError < StandardError
4
+ def initialize(cookbook_name, options)
5
+ super("Unknown cookbook reference #{cookbook_name} #{options}")
6
+ end
7
+ end
8
+
9
+ BERKSHELF_PATH_ENV = 'BERKSHELF_PATH'
10
+ def self.berkshelf_path
11
+ File.absolute_path(ENV[BERKSHELF_PATH_ENV] || "#{ENV['HOME']}/.berkshelf/")
12
+ end
13
+
14
+ class BerksLockFile
15
+ class << self
16
+ def from_file(path)
17
+ content = File.read(path)
18
+ object = new
19
+ object.load(content)
20
+ end
21
+ end
22
+
23
+ attr_reader :cookbooks
24
+
25
+ def initialize
26
+ @cookbooks = {}
27
+ end
28
+
29
+ def load(content)
30
+ instance_eval(content)
31
+ self
32
+ end
33
+
34
+ def cookbook(name, options = {})
35
+ cookbooks[name] = options
36
+ end
37
+
38
+ def create_links(cookbook_dir, berkshelf_path)
39
+ FileUtils.mkdir_p(cookbook_dir)
40
+ cookbooks.each do |name, options|
41
+ if options[:path]
42
+ target = options[:path]
43
+ elsif options[:locked_version]
44
+ target = "#{berkshelf_path}/cookbooks/#{name}-#{options[:locked_version]}"
45
+ end
46
+ if target
47
+ FileUtils.ln_s(target, "#{cookbook_dir}/#{name}", :force => true)
48
+ else
49
+ raise UnknownCookbookReferenceError.new(name, options)
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def self.create_shims(root, path=nil)
56
+ path ||= berkshelf_path
57
+ BerksLockFile::from_file("#{root}/Berksfile.lock").create_links("#{root}/cookbooks", path)
58
+ end
59
+
60
+ end
@@ -0,0 +1,89 @@
1
+ describe BerkshelfShims do
2
+ describe '#berkshelf_path' do
3
+ subject {BerkshelfShims.berkshelf_path}
4
+ it 'defaults to the user\'s home directory' do
5
+ should == "#{ENV['HOME']}/.berkshelf"
6
+ end
7
+ context 'with a BERKSHELF_PATH environment variable' do
8
+ before do
9
+ @first_env = ENV['BERKSHELF_PATH']
10
+ ENV['BERKSHELF_PATH']='/some-path'
11
+ end
12
+ after do
13
+ ENV['BERKSHELF_PATH'] = @first_env
14
+ end
15
+ it 'should respect teh environment variable' do
16
+ should == '/some-path'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#create_shims' do
22
+ let(:test_dir) {'tmp'}
23
+ let(:lock_file) {"#{test_dir}/Berksfile.lock"}
24
+ let(:cookbooks_dir) {"#{test_dir}/cookbooks"}
25
+ let(:relative_target_dir) {'/Some/Directory'}
26
+
27
+ before do
28
+ FileUtils.rm_rf(test_dir)
29
+ FileUtils.mkdir(test_dir)
30
+ File.open(lock_file, 'w') do |f|
31
+ cookbook_entries.each do |line|
32
+ f.puts line
33
+ end
34
+ end
35
+ end
36
+ context 'with a normal input' do
37
+ let(:cookbook_entries) {[
38
+ "cookbook 'relative', :path => '#{relative_target_dir}'",
39
+ "cookbook 'versioned', :locked_version => '0.0.1'"
40
+ ]}
41
+
42
+ context 'with the default berkshelf path' do
43
+ before do
44
+ BerkshelfShims::create_shims('tmp')
45
+ end
46
+ it 'creates the links' do
47
+ Dir.exists?(cookbooks_dir).should == true
48
+ Dir["#{cookbooks_dir}/*"].sort.should == ["#{cookbooks_dir}/relative", "#{cookbooks_dir}/versioned"]
49
+ File.readlink("#{cookbooks_dir}/relative").should == '/Some/Directory'
50
+ File.readlink("#{cookbooks_dir}/versioned").should == "#{BerkshelfShims.berkshelf_path}/cookbooks/versioned-0.0.1"
51
+ end
52
+ end
53
+
54
+ context 'with an explicit berkshelf path' do
55
+ before do
56
+ BerkshelfShims::create_shims('tmp', 'berkshelf')
57
+ end
58
+ it 'creates the links' do
59
+ Dir.exists?(cookbooks_dir).should == true
60
+ Dir["#{cookbooks_dir}/*"].sort.should == ["#{cookbooks_dir}/relative", "#{cookbooks_dir}/versioned"]
61
+ File.readlink("#{cookbooks_dir}/relative").should == '/Some/Directory'
62
+ File.readlink("#{cookbooks_dir}/versioned").should == "berkshelf/cookbooks/versioned-0.0.1"
63
+ end
64
+ end
65
+
66
+ context 'with an environent variable' do
67
+ before do
68
+ ENV[BerkshelfShims::BERKSHELF_PATH_ENV] = '/berkshelf_env'
69
+ BerkshelfShims::create_shims('tmp')
70
+ end
71
+ it 'creates the links' do
72
+ Dir.exists?(cookbooks_dir).should == true
73
+ Dir["#{cookbooks_dir}/*"].sort.should == ["#{cookbooks_dir}/relative", "#{cookbooks_dir}/versioned"]
74
+ File.readlink("#{cookbooks_dir}/relative").should == '/Some/Directory'
75
+ File.readlink("#{cookbooks_dir}/versioned").should == "/berkshelf_env/cookbooks/versioned-0.0.1"
76
+ end
77
+ end
78
+ end
79
+
80
+ context 'with an unknown cookbook reference' do
81
+ let(:cookbook_entries) {[
82
+ "cookbook 'relative'"
83
+ ]}
84
+ it 'throws an error' do
85
+ expect {BerkshelfShims::create_shims('tmp')}.to raise_error BerkshelfShims::UnknownCookbookReferenceError
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,8 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/vendor/'
4
+ add_filter '/spec/'
5
+ end
6
+
7
+ require 'berkshelf-shims'
8
+
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: berkshelf-shims
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Bellegarde
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Shim functionality for Berkshelf
15
+ email:
16
+ - bellegar@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rbenv-version
23
+ - .rspec
24
+ - .travis.yml
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - README.md
28
+ - Rakefile
29
+ - berkshelf-shims.gemspec
30
+ - lib/berkshelf-shims.rb
31
+ - lib/berkshelf-shims/version.rb
32
+ - spec/berkshelf_shims_spec.rb
33
+ - spec/spec_helper.rb
34
+ homepage: https://github.com/JeffBellegarde/berkshelf-shims
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ segments:
47
+ - 0
48
+ hash: -1796066710175234953
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ segments:
56
+ - 0
57
+ hash: -1796066710175234953
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.23
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Provides methods to create a cookbooks directory derived from Berksfile.lock.
64
+ test_files:
65
+ - spec/berkshelf_shims_spec.rb
66
+ - spec/spec_helper.rb