maildotyml 0.0.1 → 0.0.2

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.
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Configure ActionMailer with mail.yml, like ActiveRecord and database.yml.
4
4
 
5
+ [![Build Status](https://travis-ci.org/carnesmedia/maildotyml.png)](https://travis-ci.org/carnesmedia/maildotyml)
6
+ [![Coverage Status](https://coveralls.io/repos/carnesmedia/maildotyml/badge.png)](https://coveralls.io/r/carnesmedia/maildotyml)
7
+
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -45,7 +49,6 @@ production:
45
49
  The following features are planned for the near future:
46
50
 
47
51
  * Add a generator to create `config/mail.yml.example` with example configuration.
48
- * Better error handling (if `mail.yml` doesn't exist, or environment is not present).
49
52
  * Map common ActiveRecord configuration keys.
50
53
  (ie, `username` -> `user_name`).
51
54
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ task default: :test
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.libs << "test"
10
+ end
@@ -1,6 +1,7 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
3
  require 'active_support/core_ext/hash/keys'
4
+ require 'active_support/core_ext/object/blank'
4
5
 
5
6
  module Maildotyml
6
7
  class Configuration
@@ -10,22 +11,30 @@ module Maildotyml
10
11
  end
11
12
 
12
13
  def delivery_method
13
- parsed[:adapter]
14
+ parsed[:adapter].to_sym if parsed[:adapter]
14
15
  end
15
16
 
16
17
  def settings
17
18
  parsed.reject { |k,v| k == :adapter }
18
19
  end
19
20
 
21
+ def present?
22
+ parsed.present?
23
+ end
24
+
20
25
  private
21
26
 
22
27
  def parsed
23
28
  # TODO: What to do if there is no environment
24
- @_parsed ||= yaml.fetch(environment).symbolize_keys
29
+ @_parsed ||= yaml.fetch(environment, {}).symbolize_keys
25
30
  end
26
31
 
27
32
  def yaml
28
- YAML.load ERB.new(file.read).result
33
+ if file.exist?
34
+ YAML.load ERB.new(file.read).result
35
+ else
36
+ {}
37
+ end
29
38
  end
30
39
 
31
40
  end
@@ -1,7 +1,9 @@
1
1
  module Maildotyml
2
2
  class Railtie < ::Rails::Railtie
3
3
  initializer 'maildotyml.initialize' do |app|
4
- Maildotyml.configure(Rails.root.join('config/mail.yml'), Rails.env)
4
+ file = Rails.root.join('config/mail.yml')
5
+ configuration = Maildotyml::Configuration.new(file, Rails.env)
6
+ Maildotyml.configure(configuration)
5
7
  end
6
8
  end
7
9
  end
@@ -1,3 +1,3 @@
1
1
  module Maildotyml
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/maildotyml.rb CHANGED
@@ -2,11 +2,18 @@ require 'maildotyml/version'
2
2
  require 'maildotyml/configuration'
3
3
  require 'maildotyml/railtie' if defined?(Rails)
4
4
 
5
-
6
5
  module Maildotyml
7
- def self.configure(file, environment)
8
- configuration = Maildotyml::Configuration.new(file, environment)
9
- ActionMailer::Base.delivery_method = configuration.delivery_method
10
- ActionMailer::Base.send(:"#{configuration.delivery_method}_settings=", configuration.settings)
6
+ def self.configure(configuration, klass = ActionMailer::Base)
7
+ if configuration.present?
8
+ delivery_method = configuration.delivery_method
9
+
10
+ if klass.delivery_methods.include? delivery_method
11
+ klass.delivery_method = delivery_method
12
+ klass.send(:"#{delivery_method}_settings=", configuration.settings)
13
+ else
14
+ available_adapters = klass.delivery_methods.keys
15
+ raise ArgumentError, "ActionMailer does not support the #{delivery_method.inspect} adapter. Available adapters are: #{available_adapters.inspect}"
16
+ end
17
+ end
11
18
  end
12
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maildotyml
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:
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
88
  version: '0'
89
89
  segments:
90
90
  - 0
91
- hash: -579743184437110137
91
+ hash: -480117984576728793
92
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  none: false
94
94
  requirements:
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  version: '0'
98
98
  segments:
99
99
  - 0
100
- hash: -579743184437110137
100
+ hash: -480117984576728793
101
101
  requirements: []
102
102
  rubyforge_project:
103
103
  rubygems_version: 1.8.25