capistrano-template 0.0.4 → 0.0.5

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: d43e1e1efca15e4a2269fa8e117ebb32e10af19f
4
- data.tar.gz: 691af6de00ab337d111d2b134cdc07c78ecdb59e
3
+ metadata.gz: 4b7c26cd31e68ace9c983f2690872cf25d451575
4
+ data.tar.gz: ad40226e2f26582edd73d56ea42006076d70c292
5
5
  SHA512:
6
- metadata.gz: f3ad30092984bf23823bf4719787e88e75e075338520c62c3658e04878125c900d5724779497884b499c9b8d1764d619b453b7defd808f518e31a4e08a388def
7
- data.tar.gz: fc6fff6d4580e2f2a1feda2cd2f6a271182090f19ead695ea2287e0cc0cfdd1a83fe853a85ae0fbe6ed62e3966b80ddf9e091ae8ebd64caa48b5f73413a50b52
6
+ metadata.gz: bb0f80f4116772a04a4a711e3cb1e65ba14d8029ab651b349036253726f203791a0720f12ce1839ca5d2eb779067b2e85dbd28547c4ceb352f2c6b9bfe3c086c
7
+ data.tar.gz: f26c7fb86f05eaccb669324573288f504c8f496bc6d7c0271334f13f1c6dfbba565a9a3724da4117994042d53593029907e932d563ead7a0167b4d32436fdd4d
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .idea
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -14,9 +14,5 @@ ParameterLists:
14
14
  MethodLength:
15
15
  Max: 50
16
16
 
17
- # @see http://www.rubytapas.com/episodes/24-Incidental-Change
18
- TrailingComma:
19
- Enabled: false
20
-
21
17
  RegexpLiteral:
22
- Enabled: false
18
+ Enabled: false
@@ -1,8 +1,213 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2014-05-26 11:14:26 +0200 using RuboCop version 0.22.0.
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2016-07-27 08:41:15 +0200 using RuboCop version 0.42.0.
3
4
  # The point is for the user to remove these configuration records
4
5
  # one by one as the offenses are removed from the code base.
5
6
  # Note that changes in the inspected code, or installation of new
6
7
  # versions of RuboCop, may require this file to be generated again.
7
8
 
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 20
8
12
 
13
+ # Offense count: 2
14
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
15
+ # URISchemes: http, https
16
+ Metrics/LineLength:
17
+ Max: 223
18
+
19
+ # Offense count: 5
20
+ # Cop supports --auto-correct.
21
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
22
+ # SupportedStyles: with_first_parameter, with_fixed_indentation
23
+ Style/AlignParameters:
24
+ Exclude:
25
+ - 'lib/capistrano/template/helpers/uploader.rb'
26
+
27
+ # Offense count: 11
28
+ # Cop supports --auto-correct.
29
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
30
+ # SupportedStyles: percent_q, bare_percent
31
+ Style/BarePercentLiterals:
32
+ Exclude:
33
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
34
+ - 'spec/integration/capistrano/template/helpers/dsl_spec.rb'
35
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
36
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
37
+
38
+ # Offense count: 1
39
+ # Cop supports --auto-correct.
40
+ Style/BlockEndNewline:
41
+ Exclude:
42
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
43
+
44
+ # Offense count: 1
45
+ # Cop supports --auto-correct.
46
+ Style/ClosingParenthesisIndentation:
47
+ Exclude:
48
+ - 'lib/capistrano/template/helpers/uploader.rb'
49
+
50
+ # Offense count: 31
51
+ # Cop supports --auto-correct.
52
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
53
+ # SupportedStyles: empty_lines, no_empty_lines
54
+ Style/EmptyLinesAroundBlockBody:
55
+ Exclude:
56
+ - 'spec/integration/capistrano/template/helpers/dsl_spec.rb'
57
+ - 'spec/integration/capistrano/template/helpers/paths_lookup_spec.rb'
58
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
59
+ - 'spec/unit/capistrano/template/helpers/paths_lookup_spec.rb'
60
+ - 'spec/unit/capistrano/template/helpers/renderer_spec.rb'
61
+ - 'spec/unit/capistrano/template/helpers/template_digester_spec.rb'
62
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
63
+
64
+ # Offense count: 2
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
67
+ # SupportedStyles: consistent, special_for_inner_method_call, special_for_inner_method_call_in_parentheses
68
+ Style/FirstParameterIndentation:
69
+ Exclude:
70
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
71
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
72
+
73
+ # Offense count: 1
74
+ # Cop supports --auto-correct.
75
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
76
+ # SupportedStyles: line_count_dependent, lambda, literal
77
+ Style/Lambda:
78
+ Exclude:
79
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
80
+
81
+ # Offense count: 1
82
+ Style/MethodMissing:
83
+ Exclude:
84
+ - 'lib/capistrano/template/helpers/dsl.rb'
85
+
86
+ # Offense count: 1
87
+ # Cop supports --auto-correct.
88
+ Style/MultilineBlockLayout:
89
+ Exclude:
90
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
91
+
92
+ # Offense count: 1
93
+ # Cop supports --auto-correct.
94
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
95
+ # SupportedStyles: symmetrical, new_line, same_line
96
+ Style/MultilineMethodCallBraceLayout:
97
+ Exclude:
98
+ - 'lib/capistrano/template/helpers/dsl.rb'
99
+
100
+ # Offense count: 1
101
+ # Cop supports --auto-correct.
102
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
103
+ # SupportedStyles: symmetrical, new_line, same_line
104
+ Style/MultilineMethodDefinitionBraceLayout:
105
+ Exclude:
106
+ - 'lib/capistrano/template/helpers/uploader.rb'
107
+
108
+ # Offense count: 1
109
+ # Cop supports --auto-correct.
110
+ Style/MutableConstant:
111
+ Exclude:
112
+ - 'lib/capistrano/template/version.rb'
113
+
114
+ # Offense count: 6
115
+ # Cop supports --auto-correct.
116
+ # Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles.
117
+ # SupportedOctalStyles: zero_with_o, zero_only
118
+ Style/NumericLiteralPrefix:
119
+ Exclude:
120
+ - 'lib/capistrano/template/helpers/dsl.rb'
121
+ - 'lib/capistrano/template/helpers/uploader.rb'
122
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
123
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
124
+
125
+ # Offense count: 10
126
+ # Cop supports --auto-correct.
127
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
128
+ # SupportedStyles: lower_case_q, upper_case_q
129
+ Style/PercentQLiterals:
130
+ Exclude:
131
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
132
+ - 'spec/integration/capistrano/template/helpers/dsl_spec.rb'
133
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
134
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
135
+
136
+ # Offense count: 1
137
+ # Cop supports --auto-correct.
138
+ Style/RedundantParentheses:
139
+ Exclude:
140
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
141
+
142
+ # Offense count: 1
143
+ # Cop supports --auto-correct.
144
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
145
+ # SupportedStyles: only_raise, only_fail, semantic
146
+ Style/SignalException:
147
+ Exclude:
148
+ - 'lib/capistrano/template/helpers/dsl.rb'
149
+
150
+ # Offense count: 2
151
+ # Cop supports --auto-correct.
152
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
153
+ # SupportedStyles: space, no_space
154
+ Style/SpaceBeforeBlockBraces:
155
+ Exclude:
156
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
157
+
158
+ # Offense count: 2
159
+ # Cop supports --auto-correct.
160
+ Style/SpaceBeforeComma:
161
+ Exclude:
162
+ - 'lib/capistrano/template/helpers/uploader.rb'
163
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
164
+
165
+ # Offense count: 4
166
+ # Cop supports --auto-correct.
167
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
168
+ # SupportedStyles: space, no_space
169
+ Style/SpaceInsideBlockBraces:
170
+ Exclude:
171
+ - 'lib/capistrano/template/helpers/dsl.rb'
172
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
173
+
174
+ # Offense count: 2
175
+ # Cop supports --auto-correct.
176
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
177
+ # SupportedStyles: single_quotes, double_quotes
178
+ Style/StringLiterals:
179
+ Exclude:
180
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
181
+
182
+ # Offense count: 2
183
+ # Cop supports --auto-correct.
184
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
185
+ # SupportedStyles: final_newline, final_blank_line
186
+ Style/TrailingBlankLines:
187
+ Exclude:
188
+ - 'Gemfile'
189
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
190
+
191
+ # Offense count: 1
192
+ # Cop supports --auto-correct.
193
+ # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
194
+ # SupportedStyles: comma, consistent_comma, no_comma
195
+ Style/TrailingCommaInLiteral:
196
+ Exclude:
197
+ - 'spec/unit/capistrano/template/helpers/dsl_spec.rb'
198
+
199
+ # Offense count: 1
200
+ # Cop supports --auto-correct.
201
+ Style/UnneededInterpolation:
202
+ Exclude:
203
+ - 'spec/integration/capistrano/template/helpers/paths_lookup_spec.rb'
204
+
205
+ # Offense count: 11
206
+ # Cop supports --auto-correct.
207
+ Style/UnneededPercentQ:
208
+ Exclude:
209
+ - 'capistrano-template.gemspec'
210
+ - 'lib/capistrano/template/tasks/template_defaults.rake'
211
+ - 'spec/integration/capistrano/template/helpers/dsl_spec.rb'
212
+ - 'spec/integration/capistrano/template/helpers/uploader_spec.rb'
213
+ - 'spec/unit/capistrano/template/helpers/uploader_spec.rb'
@@ -1,6 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1
4
- - 2.0
3
+ - 2.1.5
4
+ - 2.2.1
5
+ - 2.3.1
5
6
  script: bundle exec rake spec rubocop
6
7
  cache: bundler
8
+ before_install:
9
+ - gem install bundler # -v 1.7.14 if a specific version is needed
@@ -1,4 +1,4 @@
1
- ruby=ruby-2.1.0
1
+ ruby=ruby-2.3.0
2
2
  ruby-gemset=capistrano-template
3
3
  #ruby-gem-install=bundler rake
4
4
  #ruby-bundle-install=true
@@ -0,0 +1,14 @@
1
+ 0.0.6 (Next)
2
+ =============
3
+
4
+
5
+ 0.0.5 (27/07/2016)
6
+ ==================
7
+
8
+ #### Features
9
+
10
+ * [#5](https://github.com/faber-lotto/capistrano-template/5): Enable the usage of locals.
11
+
12
+ #### Fixes
13
+
14
+ * [#4](https://github.com/faber-lotto/capistrano-template/4): Fix for `Digest::Base cannot be directly inherited in Ruby` race condition within ruby digest - [@slowjack2k](https://github.com/slowjack2k).
data/README.md CHANGED
@@ -42,7 +42,7 @@ In your Capfile:
42
42
  # searchs for template assets.host.site.erb in :templating_paths
43
43
  # renders the template and upload it to "#{release_path}/assets.host.site" on all hosts
44
44
  # when the new rendered content is changed or the remote file does not exists
45
- template 'assets.host.site'
45
+ template 'assets.host.site', locals: { 'local1' => 'value local 1'}
46
46
  end
47
47
 
48
48
  on roles :all
@@ -50,7 +50,7 @@ In your Capfile:
50
50
  # renders the template and upload it to "~/execute_some_thing.sh" on all hosts
51
51
  # when the new rendered content is changed or the remote file does not exists
52
52
  # after this the mode is changed to 0750
53
- template 'other.template.name', '~/execute_some_thing.sh', 0750
53
+ template 'other.template.name', '~/execute_some_thing.sh', 0750, locals: { 'local1' => 'value local 1'}
54
54
  end
55
55
 
56
56
  end
@@ -116,7 +116,7 @@ This settings can be changed in your Capfile, deploy.rb or stage file.
116
116
 
117
117
  | Variable | Default | Description |
118
118
  |-----------------------|---------------------------------------|---------------------------------------|
119
- |`templating_digster` | <code> -&gt;(data){ Digest::MD5.hexdigest(data)} </code> | Checksum algorythmous for rendered template to check for remote diffs |
119
+ |`templating_digster` | <code> -&gt;(data){ OpenSSL::Digest::MD5.hexdigest(data)} </code> | Checksum algorythmous for rendered template to check for remote diffs |
120
120
  |`templating_digest_cmd`| <code>%Q{test "Z$(openssl md5 %&lt;path&gt;s &#124; sed 's/^.*= *//')" = "Z%&lt;digest&gt;s" }</code> | Remote command to validate a digest. Format placeholders path is replaces by full `path` to the remote file and `digest` with the digest calculated in capistrano. |
121
121
  |`templating_mode_test_cmd` | <code>%Q{ &#91; "Z$(printf "%%.4o" 0$(stat -c "%%a" %&lt;path&gt;s 2&gt;/dev/null &#124;&#124; stat -f "%%A" %&lt;path&gt;s))" != "Z%&lt;mode&gt;s" &#93; }</code> | Test command to check the remote file permissions. |
122
122
  | `templating_paths` | <code>&#91;"config/deploy/templates/#{fetch(:stage)}/%&lt;host&gt;s",</code> <br> <code> "config/deploy/templates/#{fetch(:stage)}",</code> <br> <code> "config/deploy/templates/shared/%&lt;host&gt;s",</code> <br> <code> "config/deploy/templates/shared"&#93;</code>| Folder to look for a template to render. `<host>` is replaced by the actual host. |
@@ -2,13 +2,13 @@ module Capistrano
2
2
  module Template
3
3
  module Helpers
4
4
  module DSL
5
- def template(from, to = nil, mode = 0640)
5
+ def template(from, to = nil, mode = 0640, locals: {})
6
6
  fail ::ArgumentError, "template #{from} not found Paths: #{template_paths_lookup.paths_for_file(from).join(':')}" unless template_exists?(from)
7
7
 
8
8
  to ||= "#{release_path}/#{File.basename(from, '.erb')}"
9
9
  to = remote_path_for(to, true)
10
10
 
11
- template = _template_factory.call(template_file(from), self, fetch(:templating_digster))
11
+ template = _template_factory.call(template_file(from), self, fetch(:templating_digster), locals)
12
12
 
13
13
  _uploader_factory.call(to, self,
14
14
  digest: template.digest,
@@ -53,7 +53,7 @@ module Capistrano
53
53
  end
54
54
 
55
55
  def _template_factory
56
- ->(from, context, digester) {TemplateDigester.new(Renderer.new(from, context), digester) }
56
+ ->(from, context, digester, locals) {TemplateDigester.new(Renderer.new(from, context, locals: locals), digester) }
57
57
  end
58
58
 
59
59
  def method_missing(method_name, *args)
@@ -2,13 +2,20 @@ module Capistrano
2
2
  module Template
3
3
  module Helpers
4
4
  class Renderer < SimpleDelegator
5
- attr_accessor :from, :reader
5
+ attr_accessor :from, :reader, :locals
6
6
 
7
- def initialize(from, context, reader: File)
7
+ def initialize(from, context, reader: File, locals: {})
8
8
  super context
9
9
 
10
10
  self.from = from
11
11
  self.reader = reader
12
+ self.locals = locals
13
+ end
14
+
15
+ def locals=(new_locals)
16
+ new_locals ||= {}
17
+ new_locals = new_locals.each_with_object({}) { |(key, value), result| result[key.to_sym] = value }
18
+ @locals = new_locals
12
19
  end
13
20
 
14
21
  def as_str
@@ -19,6 +26,22 @@ module Capistrano
19
26
  StringIO.new(as_str)
20
27
  end
21
28
 
29
+ def method_missing(m, *args, &block)
30
+ if locals.key?(m)
31
+ locals[m]
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def respond_to_missing?(m, include_private)
38
+ if locals.key?(m)
39
+ true
40
+ else
41
+ super
42
+ end
43
+ end
44
+
22
45
  protected
23
46
 
24
47
  def template_content
@@ -1,6 +1,7 @@
1
1
  namespace :load do
2
+ # rubocop:disable LineLength
2
3
  task :defaults do
3
- set :templating_digster, ->{ ->(data){ Digest::MD5.hexdigest(data)} }
4
+ set :templating_digster, ->{ ->(data){ OpenSSL::Digest::MD5.hexdigest(data)} }
4
5
  set :templating_digest_cmd, %Q{test "Z$(openssl md5 %<path>s| sed 's/^.*= *//')" = "Z%<digest>s" } # alternative %Q{echo "%<digest>s %<path>s" | md5sum -c --status } should return true when the file content is the same
5
6
  set :templating_mode_test_cmd, %Q{ [ "Z$(printf "%%.4o" 0$(stat -c "%%a" %<path>s 2>/dev/null || stat -f "%%A" %<path>s))" != "Z%<mode>s" ] } # mac uses different mode formatter
6
7
  set :templating_paths , ->{ ["config/deploy/templates/#{fetch(:stage)}/%<host>s",
@@ -8,6 +9,7 @@ namespace :load do
8
9
  "config/deploy/templates/shared/%<host>s",
9
10
  "config/deploy/templates/shared"].map {|partial_path| (partial_path)} }
10
11
  end
12
+ # rubocop:enable LineLength
11
13
  end
12
14
 
13
15
 
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Template
3
- VERSION = '0.0.4'
3
+ VERSION = '0.0.5'
4
4
  end
5
5
  end
@@ -74,8 +74,9 @@ module Capistrano
74
74
 
75
75
  let(:tmp_folder) { File.join(__dir__, '..', '..', '..', 'tmp') }
76
76
 
77
- let(:template_content) { '<%=var1%> -- <%=var2%>' }
78
- let(:expected_content) { 'my -- content' }
77
+ let(:template_content) { '<%=var1%> -- <%=var2%> -- <%= my_local %>' }
78
+ let(:expected_content) { 'my -- content -- local content' }
79
+ let(:locals) { { 'my_local' => 'local content' } }
79
80
 
80
81
  let(:template_name) { 'my_template.erb' }
81
82
  let(:template_fullname) { File.join(tmp_folder, template_name) }
@@ -105,7 +106,7 @@ module Capistrano
105
106
  describe '#template' do
106
107
 
107
108
  it 'create the result file' do
108
- subject.template(template_name)
109
+ subject.template(template_name, locals: locals)
109
110
 
110
111
  expect(File.read(remote_filename)).to eq(expected_content)
111
112
  end
@@ -6,18 +6,19 @@ module Capistrano
6
6
  describe Renderer do
7
7
 
8
8
  subject do
9
- Renderer.new(template_name, context, reader: reader)
9
+ Renderer.new(template_name, context, reader: reader, locals: locals)
10
10
  end
11
11
 
12
12
  let(:context) { OpenStruct.new(var1: 'my', var2: 'content') }
13
+ let(:locals) { { 'my_local' => 'local content' } }
13
14
  let(:template_name) { 'my_template' }
14
15
  let(:reader) { double(read: template_content) }
15
- let(:template_content) { '<%=var1%> -- <%=var2%>' }
16
+ let(:template_content) { '<%=var1%> -- <%=var2%> -- <%= my_local %>' }
16
17
 
17
18
  describe '#as_str' do
18
19
 
19
20
  it 'renders a erb template' do
20
- expect(subject.as_str).to eq('my -- content')
21
+ expect(subject.as_str).to eq('my -- content -- local content')
21
22
  end
22
23
 
23
24
  end
@@ -37,6 +38,16 @@ module Capistrano
37
38
 
38
39
  end
39
40
 
41
+ describe '.respond_to?' do
42
+ it 'returns "true" when method name is a key inside the locals hash' do
43
+ expect(subject.respond_to?(:my_local)).to be_truthy
44
+ end
45
+
46
+ it 'returns "false" when method name is not a key inside the locals hash and context does not respond to this method' do
47
+ expect(subject.respond_to?(:foo)).to be_falsy
48
+ end
49
+ end
50
+
40
51
  end
41
52
  end
42
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-template
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter Späth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.2.1
172
+ rubygems_version: 2.5.1
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Erb-Template rendering and upload for capistrano 3