writer 0.4.0.1 → 0.4.1

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: 9890015c4993cd40187cf56883e6dae69561f25c
4
- data.tar.gz: 71a1b31d6d89e11cfb9f17139c890ff48fe335f7
3
+ metadata.gz: 9a3046185551339a7a5cf840529eee79c33a7b59
4
+ data.tar.gz: 1e3deb73f505f33e03a95559f8c7ddef13f42bb3
5
5
  SHA512:
6
- metadata.gz: 0708044357ca77fe16c5fc555a61e54fb07efb159194c7e6b371688a2212198f06013db36ec6313ec78ee469e5c758e8259ba3805bc18457686c904bfaf79555
7
- data.tar.gz: f0b0bf2445d488ba7ecf28bdafd127ab8892b4cfca350aeea40180ee12232f5cde346faf87153c8d1cd12d4a260e3df1eda0cf065dfa3b9ab6291cac073a8cff
6
+ metadata.gz: e6b712af7f5480d939e6ca2c2856ab5fefdcbf6e2690d44b5433bce1778d5ca8474411bdbff8d683ab57daf6d392f541de1e1101c18acbc4752f05b6efed66f2
7
+ data.tar.gz: 31ab8ede44b3adf1b09f876a0eded87ac91b9f4b55c8ca14734fcb5f4cb042be6a9fc4d62ba98c8b7565448c2292d8fec0a6ff48feeb9ac450e1aee577ff6076
@@ -8,14 +8,36 @@ module Writer
8
8
  private
9
9
  def create_file(name, content)
10
10
  File.open(name, 'w') do |f|
11
- f.puts content || template
11
+ case content
12
+ when /[A-Z]+=\w+/
13
+ f.puts template_with_variables(content)
14
+ when nil
15
+ f.puts template
16
+ else
17
+ f.puts content
18
+ end
12
19
  end
13
20
  end
14
21
 
15
22
  def template
16
23
  unless Writer.template_path.blank?
17
- File.open(Writer.template_path).read
24
+ @template ||= File.open(Writer.template_path).read
18
25
  end
19
26
  end
27
+
28
+ def template_with_variables(content)
29
+ return content if template.nil?
30
+ modified_template = template
31
+
32
+ content.split(' ').each do |k_v|
33
+ key = k_v.split('=')[0].downcase
34
+ value = k_v.split('=')[1]
35
+ puts key
36
+ puts value
37
+ modified_template.gsub!(/%{#{key}}/, value)
38
+ end
39
+
40
+ modified_template
41
+ end
20
42
  end
21
43
  end
@@ -1,3 +1,3 @@
1
1
  module Writer
2
- VERSION = "0.4.0.1"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -18,6 +18,16 @@ module Writer
18
18
  creator.create!('filename', 'hi')
19
19
  expect(file).to have_received(:puts).with('hi')
20
20
  end
21
+
22
+ context 'with variables' do
23
+ it 'fills in the variables in the template' do
24
+ allow(creator).to receive(:template) { "hello\n%{name}, you are %{trait}" }
25
+ allow(file).to receive(:puts)
26
+
27
+ creator.create!('filename', 'NAME=joe TRAIT=cool')
28
+ expect(file).to have_received(:puts).with("hello\njoe, you are cool")
29
+ end
30
+ end
21
31
  end
22
32
 
23
33
  context "without content" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Sak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport