itamae 1.1.14 → 1.1.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f972939f9cc2ebb1f3e716d7f5ce8d6fd1093451
4
- data.tar.gz: 1b68338decf45a43dcc189c4ba4e435768da4cc7
3
+ metadata.gz: eb42826bba792530fdfbde606bce17da2fe48f68
4
+ data.tar.gz: 28962bf4afabcc6d4fd72e69a554427cf787aab0
5
5
  SHA512:
6
- metadata.gz: 7e76c169cb28a705edd1040b67c60b1b3608d1647ce06a5c19a9b8b8f2cb16c8f4b046d10c0fc09c5ecaa6c6466277535de92898a316c176534d8c18933ed4e5
7
- data.tar.gz: bb3ca9502307850461f5d4b70b3651f69bea31a939dbaf9c08f54f123ab93d0a932cce692214913d89dce4914c1153e686dfd7c2854c5938b13c1e651d93287d
6
+ metadata.gz: 5179c4d4a9041b15cfa4e0373e3b6dc0c9442a7b83523debd430fc0893916cd2001be66d4665b0afaf52ca571552f8f2ed8174e64840b177c88e439616984d83
7
+ data.tar.gz: eb6a9f40068cd75fc0e78ac9f23daeb57735c92a30c98abf52e02c49111c8d36454c3006a8aa78b9794e4da844da74ad87709587819e60e8b94cfc374038aefe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v1.1.15
2
+
3
+ Features
4
+
5
+ - Implement `gem_package` resource.
6
+
1
7
  ## v1.1.14
2
8
 
3
9
  Improvements
@@ -13,6 +13,7 @@ require 'itamae/resource/local_ruby_block'
13
13
  require 'itamae/resource/git'
14
14
  require 'itamae/resource/user'
15
15
  require 'itamae/resource/group'
16
+ require 'itamae/resource/gem_package'
16
17
 
17
18
  module Itamae
18
19
  module Resource
@@ -0,0 +1,75 @@
1
+ require 'itamae'
2
+
3
+ module Itamae
4
+ module Resource
5
+ class GemPackage < Base
6
+ define_attribute :action, default: :install
7
+ define_attribute :package_name, type: String, default_name: true
8
+ define_attribute :gem_binary, type: String, default: 'gem'
9
+ define_attribute :version, type: String
10
+
11
+ def pre_action
12
+ case @current_action
13
+ when :install
14
+ attributes.installed = true
15
+ end
16
+ end
17
+
18
+ def set_current_attributes
19
+ installed = installed_gems.find {|g| g[:name] == attributes.package_name }
20
+ current.installed = !!installed
21
+
22
+ if current.installed
23
+ versions = installed[:versions]
24
+ if versions.include?(attributes.version)
25
+ current.version = attributes.version
26
+ else
27
+ current.version = versions.first
28
+ end
29
+ end
30
+ end
31
+
32
+ def action_install(action_options)
33
+ if current.installed
34
+ if attributes.version && current.version != attributes.version
35
+ install!
36
+ updated!
37
+ end
38
+ else
39
+ install!
40
+ updated!
41
+ end
42
+ end
43
+
44
+ def action_upgrade(action_options)
45
+ return if current.installed && attributes.version && current.version == attributes.version
46
+
47
+ install!
48
+ updated!
49
+ end
50
+
51
+ def installed_gems
52
+ gems = []
53
+ run_command([attributes.gem_binary, 'list', '-l']).stdout.each_line do |line|
54
+ if /\A([^ ]+) \(([^\)]+)\)\z/ =~ line.strip
55
+ name = $1
56
+ versions = $2.split(', ')
57
+ gems << {name: name, versions: versions}
58
+ end
59
+ end
60
+ gems
61
+ end
62
+
63
+ def install!
64
+ cmd = [attributes.gem_binary, 'install']
65
+ if attributes.version
66
+ cmd << '-v' << attributes.version
67
+ end
68
+ cmd << attributes.package_name
69
+
70
+ run_command(cmd)
71
+ end
72
+ end
73
+ end
74
+ end
75
+
@@ -1 +1 @@
1
- 1.1.14
1
+ 1.1.15
@@ -113,3 +113,7 @@ describe file('/tmp/created_in_redefine') do
113
113
  it { should be_file }
114
114
  its(:content) { should match(/first/) }
115
115
  end
116
+
117
+ describe command('gem list') do
118
+ its(:stdout) { should include('tzinfo (1.2.2, 1.1.0)') }
119
+ end
@@ -1,4 +1,5 @@
1
1
  include_recipe "./included.rb"
2
+ include_recipe "./included.rb" # including the same recipe is expected to be skipped.
2
3
 
3
4
  user "create itamae user" do
4
5
  uid 123
@@ -26,6 +27,16 @@ end
26
27
 
27
28
  ######
28
29
 
30
+ gem_package 'tzinfo' do
31
+ version '1.1.0'
32
+ end
33
+
34
+ gem_package 'tzinfo' do
35
+ version '1.2.2'
36
+ end
37
+
38
+ ######
39
+
29
40
  execute "echo -n > /tmp/notifies"
30
41
 
31
42
  execute "echo -n 1 >> /tmp/notifies" do
@@ -1 +1,9 @@
1
+ require 'pathname'
2
+ included_flag_file = Pathname.new("/tmp/included_rb_is_included")
3
+ if included_flag_file.exist? && included_flag_file.read == $$.to_s
4
+ raise "included.rb should not be included twice."
5
+ else
6
+ included_flag_file.write($$.to_s)
7
+ end
8
+
1
9
  execute "touch /tmp/included_recipe"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.14
4
+ version: 1.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -171,6 +171,7 @@ files:
171
171
  - lib/itamae/resource/directory.rb
172
172
  - lib/itamae/resource/execute.rb
173
173
  - lib/itamae/resource/file.rb
174
+ - lib/itamae/resource/gem_package.rb
174
175
  - lib/itamae/resource/git.rb
175
176
  - lib/itamae/resource/group.rb
176
177
  - lib/itamae/resource/link.rb