mail2frontmatter 0.0.6 → 0.1.0

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: e2060ebb3af9ea3b6792caa4423b414ed610649b
4
- data.tar.gz: e081455cbb6870923e7edb88b5c532ab1abd5ac1
3
+ metadata.gz: 050bf37a3ad7a9d3207ce8ffb89c1b204c69e90a
4
+ data.tar.gz: 4658ee6d6a02c3a7746824d9dfcd0d1a38f9db0f
5
5
  SHA512:
6
- metadata.gz: cc1a99d909e3146c48cfd094eb10f25cbaf203e317573bc5471df5bd255b2369a4f46bae17af1b7a67e3414513b4348e1ccd1119c1fa70883a54622f0b86a514
7
- data.tar.gz: 89d9ebc85b8cdee3fa1413f407310e35a05176fbe312a8aeb692bff12a55c404f6f091002e6e3e9f4d27fe0223dbfc78b21512dd0f8646fd6b4c702edb97e74e
6
+ metadata.gz: a5114ef331caf20a530462e41730ae61a2bf02bd43cf97ccfa23816a88efc7ac5409a6c50eb2e7d44997105bedbbeb125c59357a116083c8379d36d9f71d0dc0
7
+ data.tar.gz: b6f0d9125761f73d4a3aa8f94899f2c25301cea925a367971267e974a99dcd6fe25f1daeea5aab4e0ddc5b779e9bf1290438fa63eec0b7f0123cd29137368942
data/README.md CHANGED
@@ -71,16 +71,27 @@ mailman:
71
71
 
72
72
  As shown the mailman configuration are the exact options you would pass [to that gem](https://github.com/titanous/mailman/blob/master/USER_GUIDE.md).
73
73
 
74
+ There are more configuration options available, most importantly which directory mail2frontmatter will write your blog's ERB/FrontMatter to and which directory it will save attachments. If you are using Middleman and running the executable from your Middleman directory, you likely do not need to set these explicitly.
75
+
76
+ ```yaml
77
+ data_directory: /home/deploy/yoursite/source/blog
78
+ media_directory: /home/deploy/yoursite/source
79
+ ```
80
+
81
+ media_directory is a base, it will create an images, audio, and videos directory if one does not exist and save attachments there accordingly.
82
+
83
+ Again, if you are using Middleman, the defaults should work for you.
84
+
74
85
  ### Embedded Configuration
75
86
 
76
- As an alternative to using the executable, you may wish to run the watcher (a wrapper around Mailman) embedded within your own code. This may be useful if you are already running Mailman and don't want to spare the resources or if you need to custom configure Mailman.
87
+ As an alternative to using the executable, you may wish to run the watcher (a wrapper around Mailman) embedded within your own code. This may be useful if, for example, you are already running Mailman and don't want to spare the resources or if you need to custom configure Mailman.
77
88
 
78
- Instantiate ```Mail2FrontMatter::Watcher``` and pass it a configuration hash (or keep it empty). The constructor takes a block in which you can directly access the Mailman object as well. See the example below or check out the gem's code directly.
89
+ Set ```Mail2FrontMatter```'s config by passing it a hash of options (or keep it empty). The constructor also takes a block as shown below. Check out the gem's code for more details.
79
90
 
80
91
  ```ruby
81
92
  require 'mail2frontmatter'
82
93
 
83
- watcher = Mail2FrontMatter::Watcher.new({}) do |config|
94
+ Mail2FrontMatter.set_config({}) do |config|
84
95
  config[:mailman] = {
85
96
  server: imap.gmail.com
86
97
  port: 993
@@ -90,13 +101,11 @@ Instantiate ```Mail2FrontMatter::Watcher``` and pass it a configuration hash (or
90
101
  }
91
102
 
92
103
  config[:receiver] = "yourblog@yourdomain.com"
93
- config[:senders] = "youruser@yourdomain.com"
94
-
95
- ....
104
+ config[:senders] = "youruser@yourdomain.com"
96
105
  end
97
106
 
98
107
  # run it
99
- watcher.run
108
+ Mail2FrontMatter::Watcher.run
100
109
  ```
101
110
 
102
111
  ### Plugins
@@ -139,6 +148,5 @@ You should always always return metadata and body as shown since this will be pa
139
148
  ### TODO
140
149
 
141
150
  * White list sanitization by default
142
- * Full Jekyll support - PLEASE send pull requests, I want to support Jekyll as well, hence the general project name
143
- * Mail2FrontMatter::Watcher handles both configuration for the whole shebang as well as Mailman. Should be split
144
- * Some options intended to be configurable (media directory, etc) are not yet and essentially mean you can only run this from a middleman directory installation atm.
151
+ * defaults for Jekyll out of the box
152
+
@@ -9,7 +9,6 @@ stop = false
9
9
  config = nil
10
10
  options = {
11
11
  background: false,
12
- log_file: nil,
13
12
  pid_file: File.join(run_dir, 'tmp', 'pids', 'mail2frontmatter.pid')
14
13
  }
15
14
 
@@ -21,8 +20,7 @@ OptionParser.new do |opts|
21
20
  end
22
21
 
23
22
  opts.on("-cCONFIG", "--config=CONFIG", "path to configuration file, defaults to ./data/mail2frontmatter.yml") do |config_file|
24
- require 'yaml'
25
- config = YAML.load_file(config_file).symbolize_keys!
23
+ config = config_file
26
24
  end
27
25
 
28
26
  opts.on("-d", "--detach", "detach process and run in the background") do
@@ -30,7 +28,7 @@ OptionParser.new do |opts|
30
28
  end
31
29
 
32
30
  opts.on("-lLOGFILE", "--log=LOGFILE", "path to log file, defaults to STDOUT in the foreground or ./log/mail2frontmatter.log when daemonized") do |log_file|
33
- options[:log_file] = log_file
31
+ config[:log_file] = log_file
34
32
  end
35
33
 
36
34
  opts.on("-pPIDFILE", "--pid=PIDFILE", "path to pid file, defaults to ./tmp/pids/mail2frontmatter.pid") do |pid_file|
@@ -43,6 +41,7 @@ OptionParser.new do |opts|
43
41
  end
44
42
 
45
43
  opts.on_tail("-v", "--version", "Prints version") do
44
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'mail2frontmatter', 'version')
46
45
  puts Mail2FrontMatter::VERSION
47
46
  exit
48
47
  end
@@ -107,30 +106,22 @@ if options[:background]
107
106
 
108
107
  puts "daemonizing..."
109
108
 
110
- # SET LOG FILE INTERNAL
111
- watcher = Mail2FrontMatter::Watcher.new(config) do |config|
112
- if !options[:log_file]
113
- config[:log_file] = File.join(run_dir, 'log', 'mail2frontmatter.log')
114
- else
115
- config[:log_file] = options[:log_file]
116
- end
117
- end
109
+ # SET CONFIG...
110
+ Mail2FrontMatter.set_config(config)
118
111
 
119
112
  # FORK / DETACH
120
113
  runner = fork do
121
114
  File.write(options[:pid_file], Process.pid)
122
- watcher.run
115
+ Mail2FrontMatter::Watcher.run
123
116
  end
124
117
 
125
118
  Process.detach(runner)
126
119
 
127
120
  else
128
121
 
129
- # SET LOG FILE INTERNAL (REDUNDANT)
130
- watcher = Mail2FrontMatter::Watcher.new(config) do |config|
131
- config[:log_file] = !options[:log_file] ? STDOUT : options[:log_file]
132
- end
122
+ # SET CONFIG...
123
+ Mail2FrontMatter.set_config(config)
133
124
 
134
125
  # FOREGROUND
135
- watcher.run
126
+ Mail2FrontMatter::Watcher.run
136
127
  end
@@ -0,0 +1,15 @@
1
+ protocol: imap
2
+ receiver: 'receiver@example.com'
3
+ senders: 'sender@example.com'
4
+ interval: 20
5
+
6
+ preprocessors:
7
+ - key: 'broken-processor'
8
+ - key: 'fake-processor'
9
+
10
+ mailman:
11
+ server: 'imap.gmail.com'
12
+ port: 993
13
+ ssl: true
14
+ username: 'receiver@example.com'
15
+ password: 'supersecurepassword'
@@ -0,0 +1,17 @@
1
+ protocol: imap
2
+ receiver: 'receiver@example.com'
3
+ senders: 'sender@example.com'
4
+ interval: 20
5
+
6
+ preprocessors:
7
+ - key: 'fake-processor'
8
+ - key: 'fake-processor-with-options'
9
+ options:
10
+ foo: bar
11
+
12
+ mailman:
13
+ server: 'imap.gmail.com'
14
+ port: 993
15
+ ssl: true
16
+ username: 'receiver@example.com'
17
+ password: 'supersecurepassword'
@@ -0,0 +1,11 @@
1
+ protocol: imap
2
+ receiver: 'receiver@example.com'
3
+ senders: 'sender@example.com'
4
+ interval: 20
5
+
6
+ mailman:
7
+ server: 'imap.gmail.com'
8
+ port: 993
9
+ ssl: true
10
+ username: 'receiver@example.com'
11
+ password: 'supersecurepassword'
@@ -0,0 +1,10 @@
1
+ module Mail2FrontMatter
2
+ class BrokenProcessor < PreProcessor
3
+ def self.run(metadata, body)
4
+ raise NoMethodError, "because this is a test"
5
+ return metadata, body
6
+ end
7
+ end
8
+ end
9
+
10
+ Mail2FrontMatter::BrokenProcessor.register
@@ -0,0 +1,9 @@
1
+ module Mail2FrontMatter
2
+ class FakeProcessorWithOptions < PreProcessor
3
+ def self.run(metadata, body)
4
+ return metadata, body
5
+ end
6
+ end
7
+ end
8
+
9
+ Mail2FrontMatter::FakeProcessorWithOptions.register
@@ -0,0 +1,9 @@
1
+ module Mail2FrontMatter
2
+ class FakeProcessor < PreProcessor
3
+ def self.run(metadata, body)
4
+ return metadata, body
5
+ end
6
+ end
7
+ end
8
+
9
+ Mail2FrontMatter::FakeProcessor.register
@@ -1,4 +1,5 @@
1
1
  require 'mail2frontmatter/version'
2
+ require 'mail2frontmatter/configuration'
2
3
  require 'mail2frontmatter/watcher'
3
4
  require 'mail2frontmatter/parser'
4
5
  require 'mail2frontmatter/writer'
@@ -0,0 +1,91 @@
1
+ # Holds configuration and nothing more
2
+ module Mail2FrontMatter
3
+ require 'active_support/inflector'
4
+
5
+ class << self
6
+ def logger
7
+ @logger
8
+ end
9
+
10
+ def config
11
+ @config
12
+ end
13
+
14
+ def set_config(passed_config = nil, &block)
15
+ # load config from file
16
+ if passed_config.is_a?(String)
17
+ @config = YAML.load_file(passed_config).deep_symbolize_keys!
18
+
19
+ # load config from file at default data/mail2frontmatter.yml relative from run directory
20
+ elsif passed_config.is_a?(NilClass)
21
+
22
+ default_config = File.join(Dir.pwd, 'data', 'mail2frontmatter.yml')
23
+
24
+ if File.exist?(default_config)
25
+ @config = YAML.load_file(default_config).deep_symbolize_keys!
26
+ else
27
+ raise LoadError, 'no configuration given or found at ./data/mail2frontmatter.yml'
28
+ end
29
+
30
+ elsif passed_config.is_a?(Hash)
31
+ @config = passed_config
32
+
33
+ else
34
+ raise ArgumentError, 'not a valid configuration type'
35
+ end
36
+
37
+ # setup logger, use provided location
38
+ if @config[:log_file]
39
+ @logger = Logger.new(@config[:log_file])
40
+
41
+ # or a sensible default if non was provided
42
+ elsif Dir.exist?(File.join(Dir.pwd, 'log'))
43
+ @logger = Logger.new(File.join(Dir.pwd, 'log', 'mail2frontmatter.log'))
44
+
45
+ # finally fallback onto STDOUT
46
+ else
47
+ @logger = Logger.new(STDOUT)
48
+ end
49
+
50
+ # set default for data directory unless already specified
51
+ # the data directory is where the posts will be written to
52
+ unless @config[:data_directory]
53
+ # TODO
54
+ # if middleman?
55
+ @config[:data_directory] = File.join(Dir.pwd, 'source', 'blog')
56
+ # elsif jekyll?
57
+ # else
58
+ # end
59
+ end
60
+
61
+ # set default for media directory unless already specified
62
+ # the media directory is where the attachments will be saved to
63
+ unless @config[:media_directory]
64
+ # TODO
65
+ # if middleman?
66
+ @config[:media_directory] = File.join(Dir.pwd, 'source')
67
+ # elsif jekyll?
68
+ # else
69
+ # end
70
+ end
71
+
72
+ # now we yield the config object in case the user would like to overwrite any defaults
73
+ yield(@config) if block_given?
74
+
75
+ # finally, if pre-processors were specified, we can try requiring them
76
+ preprocessors = @config[:preprocessors] || []
77
+
78
+ preprocessors.each do |processor|
79
+ begin
80
+ require "mail2frontmatter/#{processor[:key]}"
81
+ rescue LoadError => e
82
+ puts "could not require specified preprocessor '#{processor[:key]}.rb', no such file in load path. Check your configuration and try again \n\n"
83
+ raise e
84
+ end
85
+
86
+ klass = "Mail2FrontMatter::#{processor[:key].underscore.camelize}".constantize.register(processor[:options] || {})
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -30,13 +30,13 @@ module Mail2FrontMatter
30
30
  if Parser::ALLOWED_TYPES.keys.include?(attachment.main_type)
31
31
 
32
32
  # save attachments
33
- media_directory = File.join(Dir.pwd, 'source', Parser::ALLOWED_TYPES[attachment.main_type])
34
- FileUtils.mkdir_p(media_directory)
33
+ media_type_directory = File.join(Mail2FrontMatter.config[:media_directory], Parser::ALLOWED_TYPES[attachment.main_type])
34
+ FileUtils.mkdir_p(media_type_directory)
35
35
 
36
- filepath = File.join(media_directory, attachment.filename)
36
+ filepath = File.join(media_type_directory, attachment.filename)
37
37
 
38
38
  # save attachment
39
- File.open(filepath, "w+b", 0644) {|f| f.write attachment.body.decoded}
39
+ File.open(filepath, "w+b", 0644) { |f| f.write attachment.body.decoded }
40
40
 
41
41
  # retain metadata
42
42
  attachments[attachment.cid] = {
@@ -9,6 +9,10 @@ module Mail2FrontMatter
9
9
 
10
10
  @@processors = Set.new
11
11
 
12
+ def self.processors
13
+ @@processors
14
+ end
15
+
12
16
  def self.register(options = {})
13
17
  raise InvalidProcessor, "run method not defined on #{self}" if !self.respond_to?(:run)
14
18
  raise ArgumentError, "options must be a hash" unless options.is_a? Hash
@@ -19,7 +23,12 @@ module Mail2FrontMatter
19
23
 
20
24
  def self.process(metadata, body)
21
25
  @@processors.each do |processor|
22
- metadata, body = processor.run(metadata, body)
26
+ begin
27
+ metadata, body = processor.run(metadata, body)
28
+ rescue StandardError => e
29
+ Mail2FrontMatter.logger.error("processor failed!")
30
+ Mail2FrontMatter.logger.error(e)
31
+ end
23
32
  end
24
33
 
25
34
  return metadata, body
@@ -1,3 +1,3 @@
1
1
  module Mail2FrontMatter
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,63 +1,23 @@
1
1
 
2
- # configures and runs Mailman
2
+ # configures and kicks off Mailman
3
3
  module Mail2FrontMatter
4
4
  require 'mailman'
5
- require 'active_support/inflector'
6
5
 
7
6
  class Watcher
8
7
 
9
- attr_accessor :logger
8
+ def self.run
9
+ mail_protocol = Mail2FrontMatter.config[:protocol] || :imap
10
+ poll_interval = Mail2FrontMatter.config[:interval] || 60
10
11
 
11
- def initialize(config = nil, &block)
12
- # load config from file
13
- if config.is_a?(String)
14
- config = YAML.load_file(config).deep_symbolize_keys!
15
-
16
- # load config from file at default data/mail2frontmatter.yml relative from run directory
17
- elsif config.is_a?(NilClass)
18
-
19
- default_config = File.join(Dir.pwd, 'data', 'mail2frontmatter.yml')
20
-
21
- if File.exist?(default_config)
22
- config = YAML.load_file(default_config).deep_symbolize_keys!
23
- else
24
- raise LoadError, 'no configuration given or found at ./data/mail2frontmatter.yml'
25
- end
26
-
27
- elsif !config.is_a?(Hash)
28
- raise ArgumentError, 'not a valid configuration type'
29
- end
30
-
31
- yield(config) if block_given?
32
-
33
- preprocessors = config.delete(:preprocessors) || []
34
- preprocessors.each do |processor|
35
-
36
- begin
37
- require "mail2frontmatter/#{processor[:key]}"
38
- rescue LoadError => e
39
- puts "could not require specified preprocessor '#{processor[:key]}.rb', no such file in load path. Check your configuration and try again \n\n"
40
- raise e
41
- end
42
-
43
- klass = "Mail2FrontMatter::#{processor[:key].underscore.classify}".constantize.register(processor[:options] || {})
44
- end
45
-
46
- mail_protocol = config.delete(:protocol) || :imap
47
- poll_interval = config.delete(:interval) || 60
48
-
49
- @receiver = config.delete(:receiver)
50
- @senders = config.delete(:senders)
51
- @logger = Logger.new(config.delete(:log_file))
12
+ @receiver = Mail2FrontMatter.config[:receiver]
13
+ @senders = Mail2FrontMatter.config[:senders]
52
14
 
53
15
  Mailman.config.poll_interval = poll_interval
54
16
  Mailman.config.ignore_stdin = true
55
17
 
56
- Mailman.config.send("#{mail_protocol}=", config[:mailman])
57
- Mailman.config.logger = @logger
58
- end
18
+ Mailman.config.send("#{mail_protocol}=", Mail2FrontMatter.config[:mailman])
19
+ Mailman.config.logger = Mail2FrontMatter.logger
59
20
 
60
- def run
61
21
  Mailman::Application.run do
62
22
  from(@senders).to(@receiver) do
63
23
  logger = Mailman.config.logger
@@ -13,14 +13,6 @@ module Mail2FrontMatter
13
13
  require 'active_support/inflector'
14
14
 
15
15
  def self.write(metadata, body)
16
-
17
- # TODO FIXME!
18
- #
19
- # this is supposed to be configurable!
20
- # get this value from a module variable!
21
- #
22
- data_directory = File.join(Dir.pwd, 'source', 'blog')
23
-
24
16
  # MAPPINGS!
25
17
  #
26
18
  # Play nice with programs which will read this data
@@ -34,7 +26,7 @@ module Mail2FrontMatter
34
26
 
35
27
  data = metadata.to_yaml + "---\n" + body
36
28
 
37
- File.write(File.join(data_directory, metadata[:filename]), data)
29
+ File.write(File.join(Mail2FrontMatter.config[:data_directory], metadata[:filename]), data)
38
30
  end
39
31
 
40
32
  end
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "mailman"
22
- spec.add_dependency "nokogiri"
23
- spec.add_dependency "activesupport"
21
+ spec.add_dependency "mailman", "~> 0.7"
22
+ spec.add_dependency "nokogiri", "~> 1.6"
23
+ spec.add_dependency "activesupport", "~> 4"
24
24
 
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "byebug" unless RUBY_VERSION =~ /1.9/
25
+ spec.add_development_dependency "rspec", "~> 3.1"
26
+ spec.add_development_dependency "byebug", "~> 3.5" unless RUBY_VERSION =~ /1.9/
27
27
  spec.add_development_dependency "bundler", "~> 1.7"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mail2FrontMatter, "configuration" do
4
+
5
+ let(:simple_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.simple.yml') }
6
+ let(:complex_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.complex.yml') }
7
+ let(:malformed_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.malformed.yml') }
8
+
9
+ it "should load a configuration by passing a YAML file location" do
10
+ expect {
11
+ Mail2FrontMatter.set_config(simple_config)
12
+ }.to_not raise_error
13
+ end
14
+
15
+ it "should load a configuration by passing a hash" do
16
+ expect {
17
+ Mail2FrontMatter.set_config({foo: 'bar'})
18
+ }.to_not raise_error
19
+ end
20
+
21
+ it "should raise an error for other types" do
22
+ expect {
23
+ Mail2FrontMatter.set_config([])
24
+ }.to raise_error
25
+ end
26
+
27
+ it "should fail loading malformed configs" do
28
+ expect {
29
+ Mail2FrontMatter.set_config(malformed_config)
30
+ }.to raise_error
31
+ end
32
+
33
+ it "should attempt to load the default configuration if nothing is passed" do
34
+ # this should attempt and fail because there is no ./data/mail2frontmatter.yml
35
+ expect {
36
+ Mail2FrontMatter.set_config do |config|
37
+ config[:foo] = 'bar'
38
+ end
39
+ }.to raise_error(LoadError)
40
+ end
41
+
42
+ end
@@ -11,32 +11,33 @@ describe Mail2FrontMatter::Parser, "parsing" do
11
11
  end
12
12
 
13
13
  it "should return an html body as a string" do
14
- Mail2FrontMatter::Parser.new(message_one).body.should match(/Charlie<br>/)
14
+ body = Mail2FrontMatter::Parser.new(message_one).body
15
+ expect(body).to match(/Charlie<br>/)
15
16
  end
16
17
 
17
18
  it "should return have an email metadata hash with a from key" do
18
19
  from = Mail2FrontMatter::Parser.new(message_one).metadata[:from]
19
- from.should eq("Kunal Shah <kunalashokshah@gmail.com>")
20
+ expect(from).to eq("Kunal Shah <kunalashokshah@gmail.com>")
20
21
  end
21
22
 
22
23
  it "should return have an email metadata hash with a to key" do
23
24
  to = Mail2FrontMatter::Parser.new(message_one).metadata[:to]
24
- to.should eq("stream@kunalashah.com")
25
+ expect(to).to eq("stream@kunalashah.com")
25
26
  end
26
27
 
27
28
  it "should return have an email metadata hash with a received key" do
28
29
  received = Mail2FrontMatter::Parser.new(message_one).metadata[:received]
29
- received.class.should eq(DateTime)
30
+ expect(received.class).to eq(DateTime)
30
31
  end
31
32
 
32
33
  it "should return have an email metadata hash with a subject key" do
33
34
  subject = Mail2FrontMatter::Parser.new(message_one).metadata[:subject]
34
- subject.should eq("295 Abandoned Elevator Shaft")
35
+ expect(subject).to eq("295 Abandoned Elevator Shaft")
35
36
  end
36
37
 
37
38
  it "should save attachments to disk" do
38
39
  attachment_path = Mail2FrontMatter::Parser.new(message_one).metadata[:attachments].first[1][:filepath]
39
- File.exist?(attachment_path).should eq(true)
40
+ expect(File.exist?(attachment_path)).to eq(true)
40
41
  end
41
42
 
42
43
  end
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mail2FrontMatter::PreProcessor, "registration" do
3
+ describe Mail2FrontMatter::PreProcessor do
4
+ let(:simple_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.simple.yml') }
5
+ let(:complex_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.complex.yml') }
6
+ let(:broken_config) { File.join(M2FM_GEM_PATH, 'fixtures', 'mail2frontmatter.broken.yml') }
7
+
8
+ let(:message_one) { Mail::Message.new(File.read(File.join(M2FM_GEM_PATH, 'fixtures', 'attachments.eml'))) }
4
9
 
5
10
  let(:invalidly_defined_preprocessor) {
6
11
  class MyInvalidProcessor < Mail2FrontMatter::PreProcessor
@@ -25,39 +30,57 @@ describe Mail2FrontMatter::PreProcessor, "registration" do
25
30
  return MyValidProcessor
26
31
  }
27
32
 
28
- # let(:invalidly_registered_preprocessor) {
29
- # class MyOtherwiseValidProcessor < Mail2FrontMatter::PreProcessor
30
- # def self.run(metadata, body)
31
- # # some modification
32
- # return metadata, body
33
- # end
34
- # end
35
-
36
- # return MyOtherwiseValidProcessor
37
- # }
38
-
39
- it "should raise errors for invalid processors" do
40
- expect {
41
- invalidly_defined_preprocessor.register({})
42
- }.to raise_error
43
- end
33
+ context "registration" do
44
34
 
45
- it "should not raise errors for valid processors" do
46
- expect {
47
- validly_defined_preprocessor.register({})
48
- }.to_not raise_error
49
- end
35
+ it "should raise errors for invalid processors" do
36
+ expect {
37
+ invalidly_defined_preprocessor.register({})
38
+ }.to raise_error
39
+ end
50
40
 
51
- it "should raise an error when registered without a hash" do
52
- expect {
53
- validly_defined_preprocessor.register(nil)
54
- }.to raise_error(ArgumentError)
55
- end
41
+ it "should not raise errors for valid processors" do
42
+ expect {
43
+ validly_defined_preprocessor.register({})
44
+ }.to_not raise_error
45
+ end
46
+
47
+ it "should raise an error when registered without a hash" do
48
+ expect {
49
+ validly_defined_preprocessor.register(nil)
50
+ }.to raise_error(ArgumentError)
51
+ end
52
+
53
+ it "should not raise an error when registered with a hash" do
54
+ expect {
55
+ validly_defined_preprocessor.register({ foo: 'bar' })
56
+ }.to_not raise_error
57
+ end
58
+
59
+ it "should load preprocessors" do
60
+ Mail2FrontMatter.set_config(complex_config)
61
+ processors = Mail2FrontMatter::PreProcessor.processors
62
+
63
+ expect(processors).to include(Mail2FrontMatter::FakeProcessor)
64
+ expect(processors).to include(Mail2FrontMatter::FakeProcessorWithOptions)
65
+ end
66
+
67
+ it "should provide preprocessors with passed options" do
68
+ Mail2FrontMatter.set_config(complex_config)
69
+ options = Mail2FrontMatter::FakeProcessorWithOptions.instance_variable_get(:@options)
56
70
 
57
- it "should not raise an error when registered with a hash" do
58
- expect {
59
- validly_defined_preprocessor.register({ foo: 'bar' })
60
- }.to_not raise_error
71
+ expect(options.class).to eq(Hash)
72
+ expect(options[:foo]).to eq("bar")
73
+ end
61
74
  end
62
75
 
63
- end
76
+ context "operation" do
77
+ it "should continue processing if an individual processor fails" do
78
+ Mail2FrontMatter.set_config(broken_config)
79
+ parser = Mail2FrontMatter::Parser.new(message_one)
80
+
81
+ expect {
82
+ metadata, body = Mail2FrontMatter::PreProcessor.process(parser.metadata, parser.body)
83
+ }.to_not raise_error
84
+ end
85
+ end
86
+ end
@@ -1,5 +1,6 @@
1
1
 
2
2
  M2FM_GEM_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+ $: << File.join(M2FM_GEM_PATH, 'fixtures')
3
4
 
4
5
  require 'yaml'
5
6
  require File.join(M2FM_GEM_PATH, 'lib', 'mail2frontmatter')
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail2frontmatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kunal Shah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mailman
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.6'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '4'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.5'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -126,14 +126,23 @@ files:
126
126
  - bin/mail2frontmatter
127
127
  - fixtures/attachments.eml
128
128
  - fixtures/attachments_inline.eml
129
+ - fixtures/mail2frontmatter.broken.yml
130
+ - fixtures/mail2frontmatter.complex.yml
131
+ - fixtures/mail2frontmatter.malformed.yml
132
+ - fixtures/mail2frontmatter.simple.yml
133
+ - fixtures/mail2frontmatter/broken-processor.rb
134
+ - fixtures/mail2frontmatter/fake-processor-with-options.rb
135
+ - fixtures/mail2frontmatter/fake-processor.rb
129
136
  - fixtures/no_attachments.eml
130
137
  - lib/mail2frontmatter.rb
138
+ - lib/mail2frontmatter/configuration.rb
131
139
  - lib/mail2frontmatter/parser.rb
132
140
  - lib/mail2frontmatter/preprocessor.rb
133
141
  - lib/mail2frontmatter/version.rb
134
142
  - lib/mail2frontmatter/watcher.rb
135
143
  - lib/mail2frontmatter/writer.rb
136
144
  - mail2frontmatter.gemspec
145
+ - spec/configuration_spec.rb
137
146
  - spec/parser_spec.rb
138
147
  - spec/preprocessor_spec.rb
139
148
  - spec/spec_helper.rb
@@ -162,6 +171,7 @@ signing_key:
162
171
  specification_version: 4
163
172
  summary: Email-to-blog parser which creates YAML FrontMatter
164
173
  test_files:
174
+ - spec/configuration_spec.rb
165
175
  - spec/parser_spec.rb
166
176
  - spec/preprocessor_spec.rb
167
177
  - spec/spec_helper.rb