projects
/
vagrant-dotfiles.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
08b150e
)
Provisioner objects created by config
author
Akshay Mankar
<akshaym@thoughtworks.com>
Sat, 12 Jan 2013 07:23:44 +0000
(12:53 +0530)
committer
Akshay Mankar
<akshaym@thoughtworks.com>
Sat, 12 Jan 2013 07:23:44 +0000
(12:53 +0530)
example/Vagrantfile
patch
|
blob
|
history
lib/copy_my_conf.rb
patch
|
blob
|
history
lib/copy_my_conf/config.rb
patch
|
blob
|
history
spec/copy_my_conf/config_spec.rb
patch
|
blob
|
history
spec/copy_my_conf_spec.rb
patch
|
blob
|
history
diff --git
a/example/Vagrantfile
b/example/Vagrantfile
index
8aa5f3f
..
07b89ee
100644
(file)
--- a/
example/Vagrantfile
+++ b/
example/Vagrantfile
@@
-5,12
+5,11
@@
require 'copy_my_conf'
#This is a sample vagrant file
Vagrant::Config.run do |config|
config.vm.box = "precise64"
#This is a sample vagrant file
Vagrant::Config.run do |config|
config.vm.box = "precise64"
- config.ssh.forward_agent = true
-
+
config.vm.provision Vagrant::Provisioners::CopyMyConf do |copy_conf|
config.vm.provision Vagrant::Provisioners::CopyMyConf do |copy_conf|
- copy_conf.ssh
= true
- copy_conf.vim
= true
- copy_conf.git
= true
+ copy_conf.ssh
+ copy_conf.vim
+ copy_conf.git
copy_conf.user_home = "/home/vagrant"
end
copy_conf.user_home = "/home/vagrant"
end
diff --git
a/lib/copy_my_conf.rb
b/lib/copy_my_conf.rb
index
8f2b889
..
7cde153
100644
(file)
--- a/
lib/copy_my_conf.rb
+++ b/
lib/copy_my_conf.rb
@@
-9,8
+9,7
@@
module Vagrant
def prepare
@to_be_copied = []
def prepare
@to_be_copied = []
- config.all_true.each do |c|
- conf = self.class.const_get(c.capitalize).new
+ config.all_enabled_attributes.each do |conf|
@to_be_copied << conf
conf.prepare env[:vm].config.vm, tmp_root
end
@to_be_copied << conf
conf.prepare env[:vm].config.vm, tmp_root
end
diff --git
a/lib/copy_my_conf/config.rb
b/lib/copy_my_conf/config.rb
index
b077607
..
23f150e
100644
(file)
--- a/
lib/copy_my_conf/config.rb
+++ b/
lib/copy_my_conf/config.rb
@@
-5,13
+5,28
@@
module Vagrant
def self.all_attributes
[:ssh, :vim, :git]
end
def self.all_attributes
[:ssh, :vim, :git]
end
- attr_accessor *all_attributes
attr_accessor :user_home
attr_accessor :user_home
- def all_true
- self.class.all_attributes.collect do |attr|
- self.send(attr) ? attr : nil
+ all_attributes.each do |attr|
+ define_method(attr) do
+ instance_variable_get_or_set(attr, CopyMyConf.const_get("#{attr.capitalize}").new)
+ end
+ end
+
+ def all_enabled_attributes
+ all_attributes.collect do |attr|
+ instance_variable_get "@#{attr}"
end.compact
end.compact
+ [@ssh, @vim, @git].compact
+ end
+
+ private
+ def all_attributes
+ self.class.all_attributes
+ end
+
+ def instance_variable_get_or_set(attr, value)
+ instance_variable_get("@#{attr}") || instance_variable_set("@#{attr}", value)
end
end
end
end
end
end
diff --git
a/spec/copy_my_conf/config_spec.rb
b/spec/copy_my_conf/config_spec.rb
index
4a2ffdc
..
5e1334d
100644
(file)
--- a/
spec/copy_my_conf/config_spec.rb
+++ b/
spec/copy_my_conf/config_spec.rb
@@
-5,11
+5,11
@@
module Vagrant::Provisioners
it "should list all the true attributes" do
config = Config.new
it "should list all the true attributes" do
config = Config.new
- config.vim
= true
- config.ssh
= true
+ config.vim
+ config.ssh
- all_
true_attributes = config.all_true
- all_
true_attributes.should =~ [:vim, :s
sh]
+ all_
enabled_attributes = config.all_enabled_attributes
+ all_
enabled_attributes.map(&:class) =~ [Vim, S
sh]
end
end
end
end
end
end
diff --git
a/spec/copy_my_conf_spec.rb
b/spec/copy_my_conf_spec.rb
index
b471ff3
..
10b0247
100644
(file)
--- a/
spec/copy_my_conf_spec.rb
+++ b/
spec/copy_my_conf_spec.rb
@@
-18,14
+18,14
@@
module Vagrant
end
it "should prepare provisioning process" do
end
it "should prepare provisioning process" do
- @config.should_receive(:all_
true).and_return([:vim
])
+ @config.should_receive(:all_
enabled_attributes).and_return([CopyMyConf::Vim.new
])
CopyMyConf::Vim.any_instance.should_receive(:prepare).with(@mock_vm, anything)
CopyMyConf.new.prepare
end
it "should provision the vm" do
CopyMyConf::Vim.any_instance.should_receive(:prepare).with(@mock_vm, anything)
CopyMyConf.new.prepare
end
it "should provision the vm" do
- @config.stub(:all_
true).and_return([:vim
])
+ @config.stub(:all_
enabled_attributes).and_return([CopyMyConf::Vim.new
])
copy_my_conf = CopyMyConf.new
CopyMyConf::Vim.any_instance.stub(:prepare)
copy_my_conf = CopyMyConf.new
CopyMyConf::Vim.any_instance.stub(:prepare)