fedux_org-stdlib 0.6.37 → 0.6.38

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: be4c511387484f5ebcf4421964588e8dd7e178df
4
- data.tar.gz: e4184422b88695bb932ef623a28667633dfd522d
3
+ metadata.gz: aa5e47bfdb9fb2bef0245b9251bc1b6568795422
4
+ data.tar.gz: b793ab10a4b1184e6e1927907ffdeade19e75f87
5
5
  SHA512:
6
- metadata.gz: 45cc4cfb8ed3eea954d2dd808ed6fe21bb50e32260b100c09f2bc866af5233c24444c78b37e73dd316d4eb9856739689eb1b48c0c1969a9bfb352898ab655266
7
- data.tar.gz: d7a394752d938915d1de5b90398ceb7f657dfaaec4a2747f9ca75b2596c0e53a2a67a91e2868be6b57373d34cd61eaebc80e1fd3030874d696f901702389dd85
6
+ metadata.gz: 6de22d0c95aa66f30bf08205e13b3507a262112d6d330c56c0760e32e0b62e8347c407d6a748a2df0f2b21d474927fc8c19860aaafd8cbebba2deef3a7541d07
7
+ data.tar.gz: 81c8a7486e8977b7f13650e5f2e2b8be0bfe25ce348915db915b050d90112fd4add22eb0937c7745ffa4e38b5daa05bd775f70473ddb0e0cd67f3b9bf743ac53
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fedux_org-stdlib (0.6.36)
4
+ fedux_org-stdlib (0.6.37)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -78,10 +78,10 @@ module FeduxOrgStdlib
78
78
  @logger = logger
79
79
  @working_directory = working_directory
80
80
 
81
- @file ||= _available_template_file
81
+ @file ||= available_template_file
82
82
 
83
83
  unless @file
84
- logger.debug "No template file found at #{_allowed_template_file_paths.to_list}, therefor I'm going to use an empty template object instead."
84
+ logger.debug "No template file found at #{allowed_template_file_paths.to_list}, therefor I'm going to use an empty template object instead."
85
85
  @content = ''
86
86
 
87
87
  return
@@ -98,7 +98,7 @@ module FeduxOrgStdlib
98
98
  # @return [String]
99
99
  # The path to the preferred template file
100
100
  def preferred_template_file
101
- _allowed_template_file_paths[1]
101
+ allowed_template_file_paths[1]
102
102
  end
103
103
 
104
104
  private
@@ -109,16 +109,16 @@ module FeduxOrgStdlib
109
109
  # The name of the template file. It defaults to `<template_name>.yaml`. If
110
110
  # you want to use a different file name you need to overwrite this
111
111
  # method.
112
- def _template_file
113
- "#{_template_name}#{_template_file_suffix}"
112
+ def template_file
113
+ "#{template_name}#{template_file_suffix}"
114
114
  end
115
115
 
116
116
  # The suffix of the template file
117
117
  #
118
118
  # @return [String]
119
119
  # The suffix of the template file
120
- def _template_file_suffix
121
- '.tt'
120
+ def template_file_suffix
121
+ '*.tt'
122
122
  end
123
123
 
124
124
  # The base name of the template
@@ -132,12 +132,12 @@ module FeduxOrgStdlib
132
132
  # class ClientTemplate; end
133
133
  #
134
134
  # This will result in `client` as base name for the template file.
135
- def _template_name
136
- unless (name = _class_name.sub(/Template/, '').underscore.singularize).blank?
135
+ def template_name
136
+ unless (name = class_name.sub(/Template/, '').underscore.singularize).blank?
137
137
  return name
138
138
  end
139
139
 
140
- fail Exceptions::ClassNameIsMissing, JSON.dump(klass: _class_name)
140
+ fail Exceptions::ClassNameIsMissing, JSON.dump(klass: class_name)
141
141
  end
142
142
 
143
143
  # The name of your application
@@ -153,8 +153,8 @@ module FeduxOrgStdlib
153
153
  # This will be converted to
154
154
  #
155
155
  # my_application
156
- def _application_name
157
- _module_name.underscore
156
+ def application_name
157
+ module_name.underscore
158
158
  end
159
159
 
160
160
  # The paths where to look for the template file
@@ -162,35 +162,62 @@ module FeduxOrgStdlib
162
162
  # @return [Array]
163
163
  # A list of paths where the template object should look for its template
164
164
  # file.
165
- def _allowed_template_file_paths
165
+ def allowed_template_file_paths
166
166
  paths = []
167
- paths << ::File.expand_path(::File.join(working_directory, 'templates', _template_file))
168
- paths << ::File.expand_path(::File.join('~', '.config', _application_name, 'templates', _template_file))
169
- paths << ::File.expand_path(::File.join('~', format('.%s', _application_name), 'templates', _template_file))
170
- paths << ::File.expand_path(::File.join('/etc', _application_name, 'templates', _template_file))
171
- paths << ::File.expand_path(::File.join(_fallback_template_directory, _template_file)) if _fallback_template_directory
167
+
168
+ paths << resolve_path(working_directory, 'templates', template_file)
169
+ paths << resolve_path('~', '.config', application_name, 'templates', template_file)
170
+ paths << resolve_path('~', format('.%s', application_name), 'templates', template_file)
171
+ paths << resolve_path('/etc', application_name, 'templates', template_file)
172
+ paths << resolve_path(fallback_template_directory, template_file) if fallback_template_directory
172
173
 
173
174
  paths
174
175
  end
175
176
 
177
+ def resolve_path(*path)
178
+ ::File.expand_path(::File.join(*path))
179
+ end
180
+
176
181
 
177
182
  # Use this path as fall back path
178
- def _fallback_template_directory; end
183
+ def fallback_template_directory; end
179
184
 
180
- def _class_name
185
+ def class_name
181
186
  self.class.name.to_s.demodulize
182
187
  end
183
188
 
184
- def _module_name
189
+ def module_name
185
190
  self.class.to_s.deconstantize
186
191
  end
187
192
 
188
- def _available_template_file
189
- _allowed_template_file_paths.find { |f| ::File.exists? f }
193
+ def available_template_file
194
+ allowed_template_file_paths.map { |f| Dir.glob(f).first }.find { |f| !f.blank? && ::File.exists?(f) }
190
195
  end
191
196
 
192
- def self._reserved_key_words
197
+ def self.reserved_key_words
193
198
  (methods | instance_methods | private_methods | private_instance_methods ) - (Class.methods | Class.private_methods ) | [:to_s]
194
199
  end
200
+
201
+ def basename
202
+ File.basename(file, '.tt')
203
+ end
204
+
205
+ def extname
206
+ File.extname(basename)
207
+ end
208
+
209
+ def extname?(*ext)
210
+ ext.any? { |e| e == extname }
211
+ end
212
+
213
+ public
214
+
215
+ def proposed_extname
216
+ ext = File.extname(basename)
217
+
218
+ return '.erb' if ext.blank?
219
+
220
+ ext
221
+ end
195
222
  end
196
223
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # FeduxOrgStdlib
3
3
  module FeduxOrgStdlib
4
- VERSION = '0.6.37'
4
+ VERSION = '0.6.38'
5
5
  end
@@ -3,22 +3,21 @@ require 'spec_helper'
3
3
  require 'fedux_org_stdlib/file_template'
4
4
 
5
5
  RSpec.describe FileTemplate do
6
-
7
6
  context '#preferred_template_file' do
8
7
  it 'has a default template file which is the preferred place to store the template' do
9
8
  with_environment 'HOME' => working_directory do
10
9
  template_klass = Class.new(FileTemplate) do
11
- def _class_name
10
+ def class_name
12
11
  'TestTemplate'
13
12
  end
14
13
 
15
- def _module_name
14
+ def module_name
16
15
  'MyApplication'
17
16
  end
18
17
  end
19
18
 
20
19
  template = template_klass.new
21
- expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/templates/test.tt')
20
+ expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/templates/test*.tt')
22
21
  end
23
22
  end
24
23
 
@@ -26,17 +25,17 @@ RSpec.describe FileTemplate do
26
25
  with_environment 'HOME' => working_directory do
27
26
  template_klass = Class.new(FileTemplate) do
28
27
 
29
- def _class_name
28
+ def class_name
30
29
  'TestTemplate'
31
30
  end
32
31
 
33
- def _module_name
32
+ def module_name
34
33
  'MyApplication::MySub'
35
34
  end
36
35
  end
37
36
 
38
37
  template = template_klass.new
39
- expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/my_sub/templates/test.tt')
38
+ expect(template.preferred_template_file).to eq File.expand_path('~/.config/my_application/my_sub/templates/test*.tt')
40
39
  end
41
40
  end
42
41
  end
@@ -49,11 +48,11 @@ RSpec.describe FileTemplate do
49
48
  EOS
50
49
 
51
50
  template_klass = Class.new(FileTemplate) do
52
- def _class_name
51
+ def class_name
53
52
  'TestTemplate'
54
53
  end
55
54
 
56
- def _module_name
55
+ def module_name
57
56
  'MyApplication'
58
57
  end
59
58
  end
@@ -70,11 +69,32 @@ RSpec.describe FileTemplate do
70
69
  EOS
71
70
 
72
71
  template_klass = Class.new(FileTemplate) do
73
- def _class_name
72
+ def class_name
73
+ 'TestTemplate'
74
+ end
75
+
76
+ def module_name
77
+ 'MyApplication'
78
+ end
79
+ end
80
+
81
+ template = template_klass.new
82
+ expect(template.content).to include 'hello world'
83
+ end
84
+ end
85
+
86
+ it 'supports star operator in suffix: ~/.my_application/templates/test*.tt' do
87
+ with_environment 'HOME' => working_directory do
88
+ create_file '.my_application/templates/test.erb.tt', <<-EOS.strip_heredoc
89
+ <%= hello world %>
90
+ EOS
91
+
92
+ template_klass = Class.new(FileTemplate) do
93
+ def class_name
74
94
  'TestTemplate'
75
95
  end
76
96
 
77
- def _module_name
97
+ def module_name
78
98
  'MyApplication'
79
99
  end
80
100
  end
@@ -93,11 +113,11 @@ RSpec.describe FileTemplate do
93
113
  EOS
94
114
 
95
115
  template_klass = Class.new(FileTemplate) do
96
- def _class_name
116
+ def class_name
97
117
  'TestTemplate'
98
118
  end
99
119
 
100
- def _module_name
120
+ def module_name
101
121
  'MyApplication'
102
122
  end
103
123
  end
@@ -107,4 +127,44 @@ RSpec.describe FileTemplate do
107
127
  end
108
128
  end
109
129
  end
130
+
131
+ context '#proposed_extname' do
132
+ it 'propose a erb as default extname' do
133
+ with_environment 'HOME' => working_directory do
134
+ create_file '.my_application/templates/test.tt'
135
+
136
+ template_klass = Class.new(FileTemplate) do
137
+ def class_name
138
+ 'TestTemplate'
139
+ end
140
+
141
+ def module_name
142
+ 'MyApplication'
143
+ end
144
+ end
145
+
146
+ template = template_klass.new
147
+ expect(template.proposed_extname).to eq '.erb'
148
+ end
149
+ end
150
+
151
+ it 'extracts the extname from file name' do
152
+ with_environment 'HOME' => working_directory do
153
+ create_file '.my_application/templates/test.md.tt'
154
+
155
+ template_klass = Class.new(FileTemplate) do
156
+ def class_name
157
+ 'TestTemplate'
158
+ end
159
+
160
+ def module_name
161
+ 'MyApplication'
162
+ end
163
+ end
164
+
165
+ template = template_klass.new
166
+ expect(template.proposed_extname).to eq '.md'
167
+ end
168
+ end
169
+ end
110
170
  end
@@ -34,6 +34,7 @@ RSpec.describe FeduxOrgStdlib::VersionManagement::RubygemVersionFile do
34
34
  # encoding: utf-8
35
35
  # MyLibrary
36
36
  module MyLibrary
37
+ # MyClass
37
38
  module MyClass
38
39
  VERSION = '0.0.0'
39
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.37
4
+ version: 0.6.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Meyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-04 00:00:00.000000000 Z
11
+ date: 2014-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport