itamae 1.0.0.beta4 → 1.0.0.beta5

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: 4aeeda7470e3841a47a420c875efb9d332f5359e
4
- data.tar.gz: 48fe841ad7c50ab056314b47e33835d506bc5e10
3
+ metadata.gz: 16430941743e871422f34e8a84999bfdd676261c
4
+ data.tar.gz: 8b937db3cfbd6baa310f0086576f46bffee03b6b
5
5
  SHA512:
6
- metadata.gz: 553a0d69d5f583903f5f09226a9084165a389efa9481a94ea057e74da50d40a1828b57f60bcf4448ccc46366d5ac6aed10504bda68fb07adea2b7d1a5668c854
7
- data.tar.gz: e14ac9b44bc9672014ef0c8d3d38eeca1a3dcbf496c07769c4a51f7c46166c9db4a6b723d5da328dcc87a24bb550e6a51d4495bec280e41048f8d593f7fea50a
6
+ metadata.gz: e74644471245614750aff1fc8c11a9f7a5b8afff95bac06f053a2ddecbe269fb0b1b57c2d105956f62358df4530b5b0e6f0cc9a08db737ce4366b92572d3af80
7
+ data.tar.gz: 821c7cbcad69cfbb44f1d0d9d8d0c17d8241cf2332fc79693f76e48beb66e9ef2f95c0514bf5e49c1e5ab9e1f84423280e0c08447015263af673b5d5c7bd8faa
@@ -54,6 +54,8 @@ module Itamae
54
54
  return
55
55
  end
56
56
 
57
+ pre_action
58
+
57
59
  set_current_attributes
58
60
  show_differences
59
61
 
@@ -113,6 +115,10 @@ module Itamae
113
115
  super
114
116
  end
115
117
 
118
+ def pre_action
119
+ # do nothing
120
+ end
121
+
116
122
  def set_current_attributes
117
123
  # do nothing
118
124
  end
@@ -126,7 +132,7 @@ module Itamae
126
132
  def show_differences
127
133
  @current_attributes.each_pair do |key, current_value|
128
134
  value = @attributes[key]
129
- if current_value == value
135
+ if current_value == value || value.nil?
130
136
  Logger.info " #{key} will not change (current value is '#{current_value}')"
131
137
  else
132
138
  Logger.info " #{key} will change from '#{current_value}' to '#{value}'"
@@ -10,17 +10,26 @@ module Itamae
10
10
  define_attribute :group, type: String
11
11
 
12
12
  def set_current_attributes
13
- if run_specinfra(:check_file_is_directory, path)
13
+ exist = run_specinfra(:check_file_is_directory, path)
14
+ @current_attributes[:exist?] = exist
15
+
16
+ if exist
14
17
  @current_attributes[:mode] = run_specinfra(:get_file_mode, path).stdout.chomp
15
18
  @current_attributes[:owner] = run_specinfra(:get_file_owner_user, path).stdout.chomp
16
19
  @current_attributes[:group] = run_specinfra(:get_file_owner_group, path).stdout.chomp
17
20
  else
18
- updated!
21
+ @current_attributes[:mode] = nil
22
+ @current_attributes[:owner] = nil
23
+ @current_attributes[:group] = nil
24
+ end
25
+
26
+ if action == :create
27
+ @attributes[:exist?] = true
19
28
  end
20
29
  end
21
30
 
22
31
  def create_action
23
- if ! run_specinfra(:check_file_is_directory, path)
32
+ if !run_specinfra(:check_file_is_directory, path)
24
33
  run_specinfra(:create_file_as_directory, path)
25
34
  end
26
35
  if attributes[:mode]
@@ -11,7 +11,7 @@ module Itamae
11
11
  define_attribute :owner, type: String
12
12
  define_attribute :group, type: String
13
13
 
14
- def create_action
14
+ def pre_action
15
15
  src = if content_file
16
16
  content_file
17
17
  else
@@ -21,14 +21,52 @@ module Itamae
21
21
  end
22
22
  end
23
23
 
24
- temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
25
- copy_file(src, temppath)
24
+ @temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
25
+ copy_file(src, @temppath)
26
+ end
27
+
28
+ def set_current_attributes
29
+ exist = run_specinfra(:check_file_is_file, path)
30
+ @current_attributes[:exist?] = exist
26
31
 
32
+ if exist
33
+ @current_attributes[:mode] = run_specinfra(:get_file_mode, path).stdout.chomp
34
+ @current_attributes[:owner] = run_specinfra(:get_file_owner_user, path).stdout.chomp
35
+ @current_attributes[:group] = run_specinfra(:get_file_owner_group, path).stdout.chomp
36
+ else
37
+ @current_attributes[:mode] = nil
38
+ @current_attributes[:owner] = nil
39
+ @current_attributes[:group] = nil
40
+ end
41
+
42
+ if action == :create
43
+ @attributes[:exist?] = true
44
+ end
45
+ end
46
+
47
+ def show_differences
48
+ super
49
+
50
+ if @current_attributes[:exist?]
51
+ diff = run_command(["diff", "-u", path, @temppath], error: false)
52
+ if diff.exit_status == 0
53
+ # no change
54
+ Logger.info " file content will not change"
55
+ else
56
+ Logger.info " diff:"
57
+ diff.stdout.each_line do |line|
58
+ Logger.info " #{line.strip}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def create_action
27
65
  if mode
28
- run_specinfra(:change_file_mode, temppath, mode)
66
+ run_specinfra(:change_file_mode, @temppath, mode)
29
67
  end
30
68
  if owner || group
31
- run_specinfra(:change_file_owner, temppath, owner, group)
69
+ run_specinfra(:change_file_owner, @temppath, owner, group)
32
70
  end
33
71
 
34
72
  if run_specinfra(:check_file_is_file, path)
@@ -37,7 +75,7 @@ module Itamae
37
75
  end
38
76
 
39
77
  # TODO: specinfra
40
- run_command(["mv", temppath, path])
78
+ run_command(["mv", @temppath, path])
41
79
  end
42
80
  end
43
81
  end
@@ -5,7 +5,7 @@ module Itamae
5
5
  class RemoteFile < File
6
6
  define_attribute :source, type: String, required: true
7
7
 
8
- def create_action
8
+ def pre_action
9
9
  content_file(::File.expand_path(source, ::File.dirname(@recipe.path)))
10
10
 
11
11
  super
@@ -7,7 +7,7 @@ module Itamae
7
7
  class Template < File
8
8
  define_attribute :source, type: String, required: true
9
9
 
10
- def create_action
10
+ def pre_action
11
11
  src = ::File.expand_path(source, ::File.dirname(@recipe.path))
12
12
  content(ERB.new(::File.read(src), nil, '-').result(binding))
13
13
 
@@ -1,3 +1,3 @@
1
1
  module Itamae
2
- VERSION = "1.0.0.beta4"
2
+ VERSION = "1.0.0.beta5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta4
4
+ version: 1.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai