itamae-plugin-recipe-anyenv 0.3.0 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc3b2a1bba61bde074722321d9ca8f4937e108eb
4
- data.tar.gz: 7d88b2ec3a381e8379bccefab6830eaccd34c329
3
+ metadata.gz: 558700ae936f294120b68c59e71f5f4be14bb7cc
4
+ data.tar.gz: 0a9a9915c9e27459353a801b6e40c9584edb1f40
5
5
  SHA512:
6
- metadata.gz: d28feda7ac103716333fc3de0094a08e7b64b29e4ae282a68549228a729db6fb1cdcb9cc34b8869ffece04901fe5bcbfaf04bbacf0f79fc68df928591ee6a43d
7
- data.tar.gz: cd6d9437ced0ac328f6c053d9a6e121814398713636c682b20ff26b578a9a247903a1994ff3153d2156a6ae6f01ee7502fa0d261ffbc3647843811e1e1648ea4
6
+ metadata.gz: f4ab5ba6b37be5d254fad601b018bfcd6ea7f0f429bed6c1c8073b964e30bff49788d7bef897d308681f6bde7ecb7b8ae26b3feb20832e5440236e072f1c25db
7
+ data.tar.gz: 0543020a986d7af6159a7ce58152cb568c866d0fdad0d59061747abd6ee09023530788b5162f3637f39225d8338c943da80494cba44bf2b2275348c09fbc4fe5
@@ -1,7 +1,24 @@
1
- DEFAULT_RBENV_ROOT = "/usr/local/anyenv".freeze
1
+ DEFAULT_RBENV_ROOT = '/usr/local/anyenv'.freeze
2
+
3
+ def run(attributes, username = nil)
4
+ init(username)
5
+
6
+ clone_anyenv
7
+ clone_anyenv_update
8
+
9
+ install_envs(attributes)
10
+ end
11
+
12
+ private
13
+
14
+ def init(username)
15
+ @username = username
16
+ @anyenv_root_path = anyenv_root(username)
17
+ @init_cmd = anyenv_init(@anyenv_root_path)
18
+ end
2
19
 
3
20
  def scheme
4
- scheme ||= node[:anyenv][:scheme] || "git"
21
+ @scheme ||= node[:anyenv][:scheme] || 'git'
5
22
  end
6
23
 
7
24
  def anyenv_root(username)
@@ -21,7 +38,7 @@ def anyenv_user_root(username)
21
38
  return node[:anyenv][:users][username][:anyenv_root]
22
39
  end
23
40
  case node[:platform]
24
- when "darwin"
41
+ when 'darwin'
25
42
  "/Users/#{username}/.anyenv"
26
43
  else
27
44
  "/home/#{username}/.anyenv"
@@ -29,50 +46,65 @@ def anyenv_user_root(username)
29
46
  end
30
47
 
31
48
  def anyenv_init(root_path)
32
- init_str = %[export ANYENV_ROOT="#{root_path}"; ]
33
- init_str << %[export PATH="#{root_path}/bin:${PATH}"; ]
34
- init_str << %[eval "$(anyenv init -)"; ]
35
- init_str
49
+ init_str = %(export ANYENV_ROOT="#{root_path}"; )
50
+ init_str << %(export PATH="#{root_path}/bin:${PATH}"; )
51
+ init_str << %(eval "$(anyenv init -)"; )
36
52
  end
37
53
 
38
- def run(attributes, username = nil)
39
- root_path = anyenv_root(username)
40
- init_cmd = anyenv_init(root_path)
41
-
42
- git root_path do
43
- user username if username
44
- repository "#{scheme}://github.com/riywo/anyenv.git"
54
+ def clone_repository(install_path, repo_path)
55
+ git install_path do
56
+ user @username if @username
57
+ repository repo_path if repo_path
58
+ not_if "test -d #{install_path}"
45
59
  end
60
+ end
46
61
 
47
- git "#{root_path}/plugins/anyenv-update" do
48
- user username
49
- repository "#{scheme}://github.com/znz/anyenv-update.git"
50
- end
62
+ def clone_anyenv
63
+ repo_path = "#{scheme}://github.com/riywo/anyenv.git"
64
+ clone_repository(@anyenv_root_path, repo_path)
65
+ end
51
66
 
52
- attributes[:install_versions].keys.each do |env|
53
- execute "install #{env}" do
54
- user username if username
55
- command "#{init_cmd} anyenv install #{env}"
56
- not_if "#{init_cmd} type #{env}"
57
- end
58
- end
67
+ def clone_anyenv_update
68
+ install_path = "#{@anyenv_root_path}/plugins/anyenv-update"
69
+ repo_path = "#{scheme}://github.com/znz/anyenv-update.git"
70
+ clone_repository(install_path, repo_path)
71
+ end
72
+
73
+ def install_envs(attributes)
74
+ attributes[:install_versions].each do |envs|
75
+ envs.each do |env, vers|
76
+ install_env(env)
59
77
 
60
- attributes[:install_versions].each do |env, vers|
61
- vers.each do |ver|
62
- execute "#{env} install #{ver}" do
63
- user username if username
64
- command "#{init_cmd} #{env} install #{ver}"
65
- not_if "#{init_cmd} #{env} versions | grep #{ver}"
78
+ vers.each do |ver|
79
+ install_env_version(env, ver)
66
80
  end
81
+
82
+ global_version(env, vers.first)
67
83
  end
68
84
  end
85
+ end
69
86
 
70
- attributes[:install_versions].each do |env, vers|
71
- execute "#{env} global #{vers.first}" do
72
- user username if username
73
- command "#{init_cmd} #{env} global #{vers.first}; " \
74
- "#{init_cmd} #{env} rehash"
75
- not_if "#{init_cmd} #{env} global | grep #{vers.first}"
76
- end
87
+ def install_env(envname)
88
+ execute "install #{envname}" do
89
+ user @username if @username
90
+ command "#{@init_cmd} anyenv install #{envname}"
91
+ not_if "#{@init_cmd} type #{envname}"
92
+ end
93
+ end
94
+
95
+ def install_env_version(envname, version)
96
+ execute "#{envname} install #{version}" do
97
+ user @username if @username
98
+ command "#{@init_cmd} #{envname} install #{version}"
99
+ not_if "#{@init_cmd} #{envname} versions | grep #{version}"
100
+ end
101
+ end
102
+
103
+ def global_version(envname, version)
104
+ execute "#{envname} global #{version}" do
105
+ user @username if @username
106
+ command "#{@init_cmd} #{envname} global #{version}; " \
107
+ "#{@init_cmd} #{envname} rehash"
108
+ not_if "#{@init_cmd} #{envname} global | grep #{version}"
77
109
  end
78
110
  end
@@ -1,5 +1,5 @@
1
1
  require 'itamae/plugin/recipe/anyenv'
2
2
 
3
- package "git"
3
+ package 'git'
4
4
 
5
5
  run(node[:anyenv])
@@ -1,6 +1,6 @@
1
1
  require 'itamae/plugin/recipe/anyenv'
2
2
 
3
- package "git"
3
+ package 'git'
4
4
 
5
5
  node[:anyenv][:users].each do |username, user_attributes|
6
6
  attributes = node[:anyenv].merge(user_attributes)
@@ -2,7 +2,7 @@ module Itamae
2
2
  module Plugin
3
3
  module Recipe
4
4
  module Anyenv
5
- VERSION = "0.3.0"
5
+ VERSION = '0.3.1'.freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-plugin-recipe-anyenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Surume
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: itamae