lib/itamae/plugin/recipe/rtn_rbenv/user.rb in itamae-plugin-recipe-rtn_rbenv-0.0.1 vs lib/itamae/plugin/recipe/rtn_rbenv/user.rb in itamae-plugin-recipe-rtn_rbenv-0.0.2

- old
+ new

@@ -1,67 +1,48 @@ # encoding: utf-8 +include_recipe './resource.rb' include_recipe 'rtn_rbenv::common' # load setting RBENV_USER = (node['rtn_rbenv']['user'] || 'vagrant') RBENV_USER_HOME = "/home/#{RBENV_USER}" RBENV_ROOT = "#{RBENV_USER_HOME}/.rbenv" RBENV_PROFILE_PATH = "#{RBENV_USER_HOME}/.bash_profile" -RBENV_BASH_SETTING = <<"EOS" -export RBENV_ROOT=#{RBENV_ROOT} -export PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH" -eval "$(rbenv init -)" -EOS - -# define -def ruby_install(version) - execute "ruby install #{version}" do - command "source #{RBENV_PROFILE_PATH} && rbenv install #{version}" - user RBENV_USER - not_if "test `source #{RBENV_PROFILE_PATH} && rbenv versions | grep '#{version}' -c` != 0" - end -end - -def gem_install(ruby_version, name, options = {}) - execute "gem install #{name}" do - command "source #{RBENV_PROFILE_PATH} && rbenv shell #{ruby_version} && gem install #{name} #{options[:version] ? "-v #{options[:version]}" : ''} #{options[:force] ? '--force' : ''}" - user RBENV_USER - end -end - # install rbenv and ruby_build -git "#{RBENV_ROOT}" do - repository 'https://github.com/sstephenson/rbenv.git' +rbenv_install RBENV_ROOT do user RBENV_USER + profile_path RBENV_PROFILE_PATH end -git "#{RBENV_ROOT}/plugins/ruby_build" do - repository 'https://github.com/sstephenson/ruby-build.git' - user RBENV_USER -end - -execute 'add rbenv settings to .bash_profile' do - command "echo '#{RBENV_BASH_SETTING}' >> #{RBENV_PROFILE_PATH}" - user RBENV_USER - not_if "test `touch #{RBENV_PROFILE_PATH} && cat #{RBENV_PROFILE_PATH} | grep 'rbenv' -c` != 0" -end - # install Ruby and Gems (node['rtn_rbenv']['versions'] || {}).each do |ruby_version, gems| - ruby_install ruby_version + ruby_install ruby_version do + user RBENV_USER + profile_path RBENV_PROFILE_PATH + end gems.each do |gem| if gem.kind_of?(Hash) - gem_install ruby_version, gem['name'], :version => gem['version'], :force => gem['force'] + gem_install gem['name'] do + self.ruby_version ruby_version + version gem['version'] if gem['version'] + force gem['force'] if gem['force'] + user RBENV_USER + profile_path RBENV_PROFILE_PATH + end else - gem_install ruby_version, gem + gem_install gem do + self.ruby_version ruby_version + user RBENV_USER + profile_path RBENV_PROFILE_PATH + end end end end # set global if node['rtn_rbenv']['global'] execute "rbenv global #{node['rtn_rbenv']['global']}" do - command "source #{RBENV_PROFILE_PATH} && rbenv global #{node['rtn_rbenv']['global']}" + command ". #{RBENV_PROFILE_PATH} && rbenv global #{node['rtn_rbenv']['global']}" user RBENV_USER end end