tobacco 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,7 +17,7 @@ module Tobacco
17
17
  end
18
18
 
19
19
  def write_content_to_file
20
- File.open(filepath, 'w') do |f|
20
+ File.open(filepath, 'wb') do |f|
21
21
  f.write content
22
22
  end
23
23
  end
@@ -41,6 +41,10 @@ module Tobacco
41
41
  callback(:on_success, modified_content)
42
42
 
43
43
  rescue => e
44
+ Tobacco.log("ErrorWriting: #{filepath}")
45
+
46
+ # Remove the empty file
47
+ File.delete(filepath) if File.exists?(filepath)
44
48
 
45
49
  error = error_object('Error Writing', modified_content, e)
46
50
  callback(:on_write_error, error)
@@ -126,7 +130,7 @@ module Tobacco
126
130
  def error_object(msg, modified_content, e)
127
131
  Tobacco::Error.new(
128
132
  msg: msg,
129
- filepath: file_path_generator.filepath,
133
+ filepath: file_path_generator.output_filepath,
130
134
  content: modified_content,
131
135
  object: e
132
136
  )
@@ -1,3 +1,3 @@
1
1
  module Tobacco
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/tobacco.rb CHANGED
@@ -27,12 +27,14 @@ module Tobacco
27
27
  end
28
28
 
29
29
  def self.log(msg)
30
- msg = "LOGGING: #{msg}"
30
+ log_msg = "\n*******************************************\n"
31
+ log_msg += "Tobacco::Log: #{msg}\n"
32
+ log_msg += "*******************************************\n"
31
33
 
32
34
  if defined? Rails
33
- Rails.logger.info(msg)
35
+ Rails.logger.info(log_msg)
34
36
  else
35
- puts msg
37
+ puts log_msg
36
38
  end
37
39
  end
38
40
  end
@@ -21,10 +21,10 @@ describe Tobacco::Smoker do
21
21
 
22
22
  context 'when content is empty' do
23
23
  let(:inhaler) { mock('inhaler', read: '') }
24
- let(:filepath) { mock('roller', content_url: '/video', filepath: '/user') }
24
+ let(:filepath) { mock('roller', content_url: '/video', output_filepath: '/user') }
25
25
 
26
26
  before do
27
- Tobacco::Inhaler.should_receive(:new).and_return(inhaler)
27
+ Tobacco::Inhaler.stub(:new).and_return(inhaler)
28
28
  subject.file_path_generator = filepath
29
29
  end
30
30
 
@@ -39,10 +39,10 @@ describe Tobacco::Smoker do
39
39
  context 'content' do
40
40
  let(:content) { 'Directly set content' }
41
41
  let(:exhaler) { mock('exhaler', write!: true) }
42
- let(:filepath) { mock('roller', content_url: '/video', filepath: '/user', output_filepath: '/desktop') }
42
+ let(:filepath) { mock('roller', content_url: '/video', output_filepath: '/desktop') }
43
43
 
44
44
  before do
45
- Tobacco::Exhaler.should_receive(:new).and_return(exhaler)
45
+ Tobacco::Exhaler.stub(:new).and_return(exhaler)
46
46
  subject.file_path_generator = filepath
47
47
  end
48
48
 
@@ -121,7 +121,7 @@ describe Tobacco::Smoker do
121
121
  let(:filepath) { mock('roller', content_url: '/video') }
122
122
 
123
123
  before do
124
- Tobacco::Inhaler.should_receive(:new).and_return(inhaler)
124
+ Tobacco::Inhaler.stub(:new).and_return(inhaler)
125
125
  subject.file_path_generator = filepath
126
126
  end
127
127
 
@@ -152,7 +152,7 @@ describe Tobacco::Smoker do
152
152
  let(:filepath) { mock('roller', content_url: '/video') }
153
153
 
154
154
  before do
155
- Tobacco::Inhaler.should_receive(:new).and_return(inhaler)
155
+ Tobacco::Inhaler.stub(:new).and_return(inhaler)
156
156
  subject.file_path_generator = filepath
157
157
  end
158
158
 
@@ -176,11 +176,11 @@ describe Tobacco::Smoker do
176
176
 
177
177
  describe '#on_read_error' do
178
178
  let(:inhaler) { mock('inhaler', read: '') }
179
- let(:filepath) { mock('roller', content_url: '/video', filepath: '/file/path') }
179
+ let(:filepath) { mock('roller', content_url: '/video', output_filepath: '/file/path') }
180
180
  let(:smoker) { Writer.new }
181
181
 
182
182
  before do
183
- Tobacco::Inhaler.should_receive(:new).and_return(inhaler)
183
+ Tobacco::Inhaler.stub(:new).and_return(inhaler)
184
184
  subject.file_path_generator = filepath
185
185
  end
186
186
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tobacco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: