winton-active_wrapper 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +22 -1
- data/active_wrapper.gemspec +9 -3
- data/gemspec.rb +3 -1
- data/lib/active_wrapper/db.rb +2 -2
- data/lib/active_wrapper/mail.rb +40 -0
- data/lib/active_wrapper.rb +19 -3
- metadata +24 -4
data/README.markdown
CHANGED
@@ -17,7 +17,7 @@ Usage
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'active_wrapper'
|
19
19
|
|
20
|
-
$db, $log = ActiveWrapper.setup(
|
20
|
+
$db, $log, $mail = ActiveWrapper.setup(
|
21
21
|
:base => File.dirname('__FILE__'),
|
22
22
|
:env => 'development',
|
23
23
|
:log => 'custom',
|
@@ -30,11 +30,13 @@ $db.migrate('001')
|
|
30
30
|
$db.migrate_reset
|
31
31
|
$log.info('log this')
|
32
32
|
$log.clear
|
33
|
+
$mail.deliver(:from => 'me@me.com', :to => 'you@you.com', :subject => 'subject', :body => 'body')
|
33
34
|
</pre>
|
34
35
|
|
35
36
|
<code>ActiveWrapper</code> looks for the following files within the <code>:base</code> directory:
|
36
37
|
|
37
38
|
* <b>config/database.yml</b>
|
39
|
+
* <b>config/mail.yml</b>
|
38
40
|
* <b>db/migrate/*.rb</b>
|
39
41
|
|
40
42
|
The <code>:env</code> option is <code>"development"</code> by default.
|
@@ -50,6 +52,25 @@ You may also set <code>:log</code> to false to disable logging entirely.
|
|
50
52
|
|
51
53
|
Setting <code>:stdout</code> to true causes stdout and stderr to redirect to the logger. It is false by default.
|
52
54
|
|
55
|
+
Mailer
|
56
|
+
------
|
57
|
+
|
58
|
+
Your <b>mail.yml</b> should look something like this:
|
59
|
+
|
60
|
+
<pre>
|
61
|
+
development:
|
62
|
+
smtp:
|
63
|
+
address: smtp.gmail.com
|
64
|
+
authentication: :plain
|
65
|
+
domain: gmail.com
|
66
|
+
password: password
|
67
|
+
port: 587
|
68
|
+
enable_starttls_auto: true
|
69
|
+
user_name: user@gmail.com
|
70
|
+
</pre>
|
71
|
+
|
72
|
+
This file is optional.
|
73
|
+
|
53
74
|
Rakefile
|
54
75
|
--------
|
55
76
|
|
data/active_wrapper.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{active_wrapper}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Winton Welsh"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-27}
|
10
10
|
s.email = %q{mail@wintoni.us}
|
11
11
|
s.extra_rdoc_files = ["README.markdown"]
|
12
|
-
s.files = ["active_wrapper.gemspec", "gemspec.rb", "lib", "lib/active_wrapper", "lib/active_wrapper/db.rb", "lib/active_wrapper/log.rb", "lib/active_wrapper/tasks.rb", "lib/active_wrapper.rb", "MIT-LICENSE", "Rakefile", "README.markdown", "resources", "resources/migration.template", "spec", "spec/spec.opts", "spec/spec_helper.rb"]
|
12
|
+
s.files = ["active_wrapper.gemspec", "gemspec.rb", "lib", "lib/active_wrapper", "lib/active_wrapper/db.rb", "lib/active_wrapper/log.rb", "lib/active_wrapper/mail.rb", "lib/active_wrapper/tasks.rb", "lib/active_wrapper.rb", "MIT-LICENSE", "Rakefile", "README.markdown", "resources", "resources/migration.template", "spec", "spec/spec.opts", "spec/spec_helper.rb"]
|
13
13
|
s.homepage = %q{http://github.com/winton/active_wrapper}
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
s.rubygems_version = %q{1.3.1}
|
@@ -20,8 +20,14 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.specification_version = 2
|
21
21
|
|
22
22
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
23
|
+
s.add_runtime_dependency(%q<activerecord>, ["= 2.3.2"])
|
24
|
+
s.add_runtime_dependency(%q<actionmailer>, ["= 2.3.2"])
|
23
25
|
else
|
26
|
+
s.add_dependency(%q<activerecord>, ["= 2.3.2"])
|
27
|
+
s.add_dependency(%q<actionmailer>, ["= 2.3.2"])
|
24
28
|
end
|
25
29
|
else
|
30
|
+
s.add_dependency(%q<activerecord>, ["= 2.3.2"])
|
31
|
+
s.add_dependency(%q<actionmailer>, ["= 2.3.2"])
|
26
32
|
end
|
27
33
|
end
|
data/gemspec.rb
CHANGED
@@ -7,11 +7,13 @@ GEM_SPEC = Gem::Specification.new do |s|
|
|
7
7
|
s.homepage = "http://github.com/winton/#{GEM_NAME}"
|
8
8
|
s.summary = "Wraps ActiveRecord and Logger for use in non-Rails environments"
|
9
9
|
# == CONFIGURE ==
|
10
|
+
s.add_dependency('activerecord', '=2.3.2')
|
11
|
+
s.add_dependency('actionmailer', '=2.3.2')
|
10
12
|
s.extra_rdoc_files = [ "README.markdown" ]
|
11
13
|
s.files = GEM_FILES.to_a
|
12
14
|
s.has_rdoc = false
|
13
15
|
s.name = GEM_NAME
|
14
16
|
s.platform = Gem::Platform::RUBY
|
15
17
|
s.require_path = "lib"
|
16
|
-
s.version = "0.1.
|
18
|
+
s.version = "0.1.2"
|
17
19
|
end
|
data/lib/active_wrapper/db.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActiveWrapper
|
2
|
+
class Mail
|
3
|
+
|
4
|
+
attr_reader :base, :env, :config
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@base = options[:base]
|
8
|
+
@env = options[:env].to_s
|
9
|
+
|
10
|
+
path = "#{base}/config/mail.yml"
|
11
|
+
|
12
|
+
if File.exists?(path)
|
13
|
+
@config = YAML::load(File.open(path))
|
14
|
+
if @config && @config = @config[@env]
|
15
|
+
|
16
|
+
@config = @config.to_options
|
17
|
+
@config[:imap] = @config[:imap].to_options if @config[:imap]
|
18
|
+
@config[:smtp] = @config[:smtp].to_options if @config[:smtp]
|
19
|
+
if @config[:smtp]
|
20
|
+
ActionMailer::Base.delivery_method = :smtp
|
21
|
+
ActionMailer::Base.smtp_settings = @config[:smtp]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def deliver(options)
|
28
|
+
Mailer.deliver_email(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
class Mailer < ActionMailer::Base
|
32
|
+
def email(options)
|
33
|
+
from options[:from]
|
34
|
+
recipients options[:to]
|
35
|
+
subject options[:subject]
|
36
|
+
body options[:body]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/active_wrapper.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/../vendor/*/lib"].each do |path|
|
2
|
+
$:.unshift path
|
3
|
+
end
|
4
|
+
|
1
5
|
require 'rubygems'
|
6
|
+
gem 'activerecord', '=2.3.2'
|
7
|
+
gem 'actionmailer', '=2.3.2'
|
2
8
|
require 'activerecord'
|
9
|
+
require 'actionmailer'
|
3
10
|
require 'logger'
|
4
11
|
require 'yaml'
|
5
12
|
|
6
13
|
require File.dirname(__FILE__) + "/active_wrapper/db"
|
7
14
|
require File.dirname(__FILE__) + "/active_wrapper/log"
|
15
|
+
require File.dirname(__FILE__) + "/active_wrapper/mail"
|
8
16
|
|
9
17
|
module ActiveWrapper
|
10
18
|
class <<self
|
@@ -14,10 +22,18 @@ module ActiveWrapper
|
|
14
22
|
options = {
|
15
23
|
:base => File.dirname($0),
|
16
24
|
:env => 'development',
|
17
|
-
:log => 'development'
|
25
|
+
:log => options[:env] || 'development'
|
18
26
|
}.merge(options.reject { |k, v| v.nil? })
|
27
|
+
|
28
|
+
db = Db.new(options)
|
29
|
+
log = Log.new(options)
|
30
|
+
mail = Mail.new(options)
|
31
|
+
|
32
|
+
ActionMailer::Base.logger = log
|
19
33
|
|
20
|
-
[
|
34
|
+
[ db, log, mail ]
|
21
35
|
end
|
22
36
|
end
|
23
|
-
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ActiveRecord::Base.default_timezone = :utc
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winton-active_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -9,10 +9,29 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.2
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: actionmailer
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.2
|
34
|
+
version:
|
16
35
|
description:
|
17
36
|
email: mail@wintoni.us
|
18
37
|
executables: []
|
@@ -28,6 +47,7 @@ files:
|
|
28
47
|
- lib/active_wrapper
|
29
48
|
- lib/active_wrapper/db.rb
|
30
49
|
- lib/active_wrapper/log.rb
|
50
|
+
- lib/active_wrapper/mail.rb
|
31
51
|
- lib/active_wrapper/tasks.rb
|
32
52
|
- lib/active_wrapper.rb
|
33
53
|
- MIT-LICENSE
|