bib-vagrant 0.0.1

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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+
6
+ script:
7
+ - bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bib-vagrant.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 till
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Bib::Vagrant
2
+
3
+ [![Build Status](https://travis-ci.org/easybiblabs/bib-vagrant.png?branch=master)](https://travis-ci.org/easybiblabs/bib-vagrant)
4
+ [![Coverage Status](https://coveralls.io/repos/easybiblabs/bib-vagrant/badge.png)](https://coveralls.io/r/easybiblabs/bib-vagrant)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'bib-vagrant'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install bib-vagrant
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
4
+ require "bundler/gem_tasks"
5
+ require "minitest/autorun"
6
+
7
+ Encoding.default_external = Encoding::UTF_8
8
+ Encoding.default_internal = Encoding::UTF_8
9
+
10
+ task :test do
11
+ $LOAD_PATH.unshift('lib', 'test')
12
+ Dir.glob('./test/*_test.rb') do |f|
13
+ require f
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bib/vagrant/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bib-vagrant"
8
+ spec.version = Bib::Vagrant::VERSION
9
+ spec.authors = ["till"]
10
+ spec.email = ["till@php.net"]
11
+ spec.description = "A rubygem to centralize configuration and setup in every project's Vagrantfile"
12
+ spec.summary = "Centralize configuration and setup"
13
+ spec.homepage = "https://github.com/easybiblabs/bib-vagrant"
14
+ spec.license = "BSD"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'thor', '>= 0.18.1'
22
+ spec.add_dependency 'colored', '>= 1.2'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest", "~> 5.0.8"
27
+ spec.add_development_dependency "coveralls"
28
+ end
data/bin/bib-vagrant ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'bib/vagrant'
5
+ require 'colored'
6
+
7
+ Encoding.default_external = Encoding::UTF_8
8
+ Encoding.default_internal = Encoding::UTF_8
9
+
10
+ begin
11
+ BibVagrant.start
12
+ rescue => the_error
13
+ puts the_error.to_s.white_on_red
14
+ exit 1
15
+ end
@@ -0,0 +1,99 @@
1
+ require 'yaml'
2
+
3
+ module Bib
4
+ module Vagrant
5
+ class Config
6
+
7
+ @@home_dir = nil
8
+ @@verbose = true
9
+
10
+ def initialize(home = "~", verbose = true)
11
+ @@home = home
12
+ @@verbose = verbose
13
+ end
14
+
15
+ def get
16
+ vagrantconfig = get_defaults
17
+
18
+ begin
19
+ localconfigfile = File.open(get_path, 'r')
20
+ vagrantconfig.merge!(YAML.load(localconfigfile.read))
21
+ rescue Errno::ENOENT
22
+ puts 'WARNING: No vagrant user-config found, using default cookbook path' if @@verbose
23
+ create(get_path, vagrantconfig)
24
+ end
25
+
26
+ return vagrantconfig
27
+ end
28
+
29
+ def has?
30
+ File.exists?(get_path)
31
+ end
32
+
33
+ def get_path
34
+ File.expand_path("#{@@home}/.config/easybib/vagrantdefault.yml")
35
+ end
36
+
37
+ def validate!(config)
38
+
39
+ current_config_keys = config.keys
40
+
41
+ get_defaults.keys.each do |required_key|
42
+ raise "Missing #{required_key}!" unless current_config_keys.include?(required_key)
43
+ end
44
+
45
+ errors = []
46
+ log_level = ['debug', 'info', 'warn', 'error', 'fatal']
47
+
48
+ errors << "nfs: must be a boolean" unless [TrueClass, FalseClass].include?(config['nfs'].class)
49
+ errors << "gui: must be a boolean" unless [TrueClass, FalseClass].include?(config['gui'].class)
50
+ errors << "cookbook_path: does not exist" unless File.directory?(config['cookbook_path'])
51
+ errors << "chef_log_level: must be one of #{log_level.join}" unless log_level.include?(config['chef_log_level'])
52
+
53
+ if !config['additional_json'].empty?
54
+ errors << "additional_json: must be empty or valid json" unless is_valid_json?(config['additional_json'])
55
+ end
56
+
57
+ if errors.count == 0
58
+ return true
59
+ end
60
+
61
+ raise "Errors: #{errors.join(', ')}"
62
+ end
63
+
64
+ private
65
+ def create(localconfigpath, vagrantconfig)
66
+ begin
67
+ FileUtils.mkdir_p(File.dirname(localconfigpath))
68
+ File.open(localconfigpath, 'w+') do |file|
69
+ file.write( vagrantconfig.to_yaml )
70
+ puts "INFO: Created default vagrant user-config in #{localconfigpath}" if @@verbose
71
+ puts "INFO: You probably want to fix the path to the cookbooks in this file." if @@verbose
72
+ end
73
+ rescue
74
+ puts "WARNING: Unable to create default #{localconfigpath} - please do it manually." if @@verbose
75
+ end
76
+ end
77
+
78
+ def get_defaults
79
+ {
80
+ "nfs" => false,
81
+ "cookbook_path" => '~/Sites/easybib/cookbooks',
82
+ "chef_log_level" => 'debug',
83
+ "additional_json" => '{}',
84
+ "gui" => false
85
+ }
86
+ end
87
+
88
+ def is_valid_json?(json)
89
+ begin
90
+ JSON.parse(json)
91
+ return true
92
+ rescue JSON::ParserError
93
+ false
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module Bib
2
+ module Vagrant
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require "bib/vagrant/version"
2
+ require "bib/vagrant/config"
3
+ require "thor"
4
+
5
+ class BibVagrant < Thor
6
+ package_name 'bib-vagrant'
7
+
8
+ desc 'validate', 'validate the local configuration'
9
+ def validate
10
+ config = get_wrapper
11
+
12
+ vagrant_defaults = config.get
13
+ config.validate!(vagrant_defaults)
14
+
15
+ end
16
+
17
+ desc 'show', 'show configuration settings'
18
+ def show
19
+ config = get_wrapper
20
+
21
+ puts "Your configuration is located in: #{config.get_path}"
22
+ puts ""
23
+
24
+ config.get.each do |config_key,config_value|
25
+ puts "#{config_key}: #{config_value}"
26
+ end
27
+ end
28
+
29
+ desc 'setup', 'setup local configuration with default values'
30
+ def setup
31
+ config = Bib::Vagrant::Config.new
32
+ raise "Your configuration is already created: #{config.get_path}" if config.has?
33
+
34
+ config.get
35
+
36
+ puts "Configuration created in #{config.get_path}!"
37
+ end
38
+
39
+ private
40
+ def get_wrapper
41
+ config = Bib::Vagrant::Config.new
42
+ raise "No configuration, run `bib-vagrant setup`!" unless config.has?
43
+ config
44
+ end
45
+ end
@@ -0,0 +1,65 @@
1
+ require 'bib/vagrant/config'
2
+
3
+ class ConfigTest < Minitest::Test
4
+
5
+ @@fixture_dir = nil
6
+
7
+ def setup
8
+ @@fixture_dir = File.dirname(__FILE__) + "/fixtures"
9
+
10
+ FileUtils.mkdir @@fixture_dir
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.rm_rf @@fixture_dir if File.exists?(@@fixture_dir)
15
+ end
16
+
17
+ def test_config
18
+
19
+ c = Bib::Vagrant::Config.new(@@fixture_dir, false)
20
+ assert_equal(false, c.has?)
21
+
22
+ vagrant_config = c.get
23
+
24
+ assert(File.exists?("#{@@fixture_dir}/.config/easybib/vagrantdefault.yml"))
25
+ assert_kind_of(Hash, vagrant_config)
26
+
27
+ assert_equal(false, vagrant_config["nfs"])
28
+ assert_equal("~/Sites/easybib/cookbooks", vagrant_config["cookbook_path"])
29
+ assert_equal("debug", vagrant_config["chef_log_level"])
30
+ assert_equal("{}", vagrant_config["additional_json"])
31
+ assert_equal(false, vagrant_config["gui"])
32
+
33
+ end
34
+
35
+ # I wish I knew how to write a data provider with minitest
36
+ def test_validate!
37
+ config = {
38
+ "nfs" => "yes",
39
+ "gui" => false,
40
+ "cookbook_path" => "/this/does/not/exist",
41
+ "chef_log_level" => "debug",
42
+ "additional_json" => ""
43
+ }
44
+
45
+ c = Bib::Vagrant::Config.new(@@fixture_dir, false)
46
+ vagrant_config = c.get
47
+
48
+ assert_raises(RuntimeError) {
49
+ c.validate!(config)
50
+ }
51
+
52
+ config["nfs"] = false
53
+ config["cookbook_path"] = @@fixture_dir
54
+
55
+ assert(c.validate!(config))
56
+
57
+ config["additional_json"] = "{'hello'}"
58
+
59
+ assert_raises(RuntimeError) {
60
+ c.validate!(config)
61
+ }
62
+
63
+ end
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bib-vagrant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - till
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.18.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.18.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: colored
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '1.2'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '1.2'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 5.0.8
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 5.0.8
94
+ - !ruby/object:Gem::Dependency
95
+ name: coveralls
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A rubygem to centralize configuration and setup in every project's Vagrantfile
111
+ email:
112
+ - till@php.net
113
+ executables:
114
+ - bib-vagrant
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .travis.yml
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bib-vagrant.gemspec
125
+ - bin/bib-vagrant
126
+ - lib/bib/vagrant.rb
127
+ - lib/bib/vagrant/config.rb
128
+ - lib/bib/vagrant/version.rb
129
+ - test/config_test.rb
130
+ homepage: https://github.com/easybiblabs/bib-vagrant
131
+ licenses:
132
+ - BSD
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.23
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Centralize configuration and setup
155
+ test_files:
156
+ - test/config_test.rb