no_notifier_needed 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,23 @@
1
+ module NoNotifierNeeded
2
+ module Config
3
+
4
+ VALID_OPTIONS_KEYS = [
5
+ :from,
6
+ :bcc,
7
+ :reply_to,
8
+ :host,
9
+ :controller,
10
+ :action
11
+ ].freeze
12
+
13
+ # @private
14
+ attr_accessor *VALID_OPTIONS_KEYS
15
+
16
+ # Create a hash of options and their values
17
+ def options
18
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
19
+ option.merge!(key => send(key))
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,10 +3,13 @@ module NoNotifierNeeded
3
3
  initializer "Include code in controller" do
4
4
  ActiveSupport.on_load(:action_controller) do
5
5
 
6
+ #TODO
7
+ #Pass defaults to allow for this to work
6
8
  #::ActionMailer::Base.send(:include, ActionView::Helpers::)
7
- ::ActionMailer::Base.send(:include, Rails.application.routes.url_helpers) # brings ActionDispatch::Routing::UrlFor
8
- ::ActionMailer::Base.send(:include, ActionView::Helpers::UrlHelper)
9
- ::ActionMailer::Base.send(:include, ActionView::Helpers::TextHelper)
9
+
10
+ NoNotifierNeeded::Sender.send(:include, Rails.application.routes.url_helpers) # brings ActionDispatch::Routing::UrlFor
11
+ NoNotifierNeeded::Sender.send(:include, ActionView::Helpers::UrlHelper)
12
+ NoNotifierNeeded::Sender.send(:include, ActionView::Helpers::TextHelper)
10
13
  end
11
14
  end
12
15
  end
@@ -15,19 +15,5 @@ module NoNotifierNeeded
15
15
  time_from_now = what_time.is_a?(Time) ? what_time : Chronic.parse(what_time)
16
16
  Resque.enqueue_at(time_from_now, EmailProcessor, email_hash)
17
17
  end
18
-
19
- def mcp(email_name, args)
20
- @template = EmailTemplate.find_by_name(email_name)
21
- raise "Email Template name not found" if @template.nil?
22
-
23
- args_to_instance_vars(args)
24
-
25
-
26
- mail_is = ActionMailer::Base.mail(get_send_hash) do|format|
27
- format.html { render :inline => render_template_body_type(@template) }
28
- end
29
-
30
- return mail_is
31
- end
32
18
  end
33
19
  end
@@ -0,0 +1,16 @@
1
+ module NoNotifierNeeded
2
+ module Sender
3
+ def mcp(email_name, args)
4
+ template = EmailTemplate.find_by_name(email_name)
5
+ raise "Email Template name not found" if template.nil?
6
+
7
+ args_to_instance_vars(args)
8
+
9
+ mail_is = mail(get_send_hash) do|format|
10
+ format.html { render :inline => render_template_body_type(template) }
11
+ end
12
+
13
+ return mail_is
14
+ end
15
+ end
16
+ end
@@ -21,10 +21,7 @@ module NoNotifierNeeded
21
21
  end
22
22
 
23
23
  def get_send_hash
24
- mailers = ActiveSupport::DescendantsTracker.descendants(ActionMailer::Base)
25
- send_hash = {}
26
-
27
- send_hash.merge!(mailers.first.default)
24
+ send_hash = base_send_hash
28
25
  send_hash[:subject] = render_template_subject_type(@template)
29
26
  send_hash[:to] = @to.nil? ? @user.email : @to
30
27
  send_hash[:from] = @from unless @from.nil?
@@ -32,10 +29,16 @@ module NoNotifierNeeded
32
29
  send_hash
33
30
  end
34
31
 
32
+ def base_send_hash
33
+ base = {}
34
+ NoNotifierNeeded::Config::VALID_OPTIONS_KEYS.each do |k|
35
+ base[k] = NoNotifierNeeded.send(k)
36
+ end
37
+ base
38
+ end
39
+
35
40
  def args_to_instance_vars(args)
36
41
  #take each key, if a model, make it an @#{model} = model.find(value)
37
- known_models = ActiveRecord::Base.send( :subclasses )
38
-
39
42
  #else make it a @#{name}=#{value}
40
43
  args.each do |k,v|
41
44
  if Object.const_defined?(k.classify) && known_models.include?(k.classify.constantize)
@@ -50,9 +53,11 @@ module NoNotifierNeeded
50
53
  end
51
54
  end
52
55
 
53
- def translate_to_hash(which_email, args)
54
- known_models = ActiveRecord::Base.send( :subclasses )
56
+ def known_models
57
+ @known_models || @known_models = ActiveRecord::Base.send( :subclasses )
58
+ end
55
59
 
60
+ def translate_to_hash(which_email, args)
56
61
  th = {}
57
62
  th[:which_email] = which_email
58
63
 
@@ -1,14 +1,34 @@
1
1
  require 'no_notifier_needed/send'
2
2
  require 'no_notifier_needed/translate'
3
3
  require 'no_notifier_needed/render'
4
-
4
+ require 'no_notifier_needed/config'
5
+ require 'no_notifier_needed/sender'
5
6
 
6
7
  module NoNotifierNeeded
7
- include NoNotifierNeeded::Send
8
- include NoNotifierNeeded::Translate
9
- include NoNotifierNeeded::Render
8
+ extend Config
9
+ extend Send
10
+ # include Render
11
+ # include Translate
12
+ # include Sender
13
+
14
+ def self.sender(options={})
15
+ NoNotifierNeeded::Sender.new(options)
16
+ end
17
+
18
+ def self.configure
19
+ yield self
20
+ end
21
+
22
+ def self.method_missing(method, *args, &block)
23
+ return super unless sender.respond_to?(method)
24
+ sender.send(method, *args, &block)
25
+ end
10
26
 
27
+ # Delegate to Instagram::Client
28
+ def self.respond_to?(method)
29
+ return sender.respond_to?(method) || super
30
+ end
11
31
  end
12
32
 
13
33
  require 'no_notifier_needed/railtie.rb' if defined?(Rails)
14
- ::ActionMailer::Base.extend NoNotifierNeeded
34
+ #::ActionMailer::Base.extend NoNotifierNeeded
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "no_notifier_needed"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robert R. Meyer"]
12
- s.date = "2013-01-09"
12
+ s.date = "2013-01-11"
13
13
  s.description = "A work in progress"
14
14
  s.email = "Blue.Dog.Archolite@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -28,9 +28,11 @@ Gem::Specification.new do |s|
28
28
  "Rakefile",
29
29
  "VERSION",
30
30
  "lib/no_notifier_needed.rb",
31
+ "lib/no_notifier_needed/config.rb",
31
32
  "lib/no_notifier_needed/railtie.rb",
32
33
  "lib/no_notifier_needed/render.rb",
33
34
  "lib/no_notifier_needed/send.rb",
35
+ "lib/no_notifier_needed/sender.rb",
34
36
  "lib/no_notifier_needed/translate.rb",
35
37
  "no_notifier_needed.gemspec",
36
38
  "test/helper.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: no_notifier_needed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-09 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -142,9 +142,11 @@ files:
142
142
  - Rakefile
143
143
  - VERSION
144
144
  - lib/no_notifier_needed.rb
145
+ - lib/no_notifier_needed/config.rb
145
146
  - lib/no_notifier_needed/railtie.rb
146
147
  - lib/no_notifier_needed/render.rb
147
148
  - lib/no_notifier_needed/send.rb
149
+ - lib/no_notifier_needed/sender.rb
148
150
  - lib/no_notifier_needed/translate.rb
149
151
  - no_notifier_needed.gemspec
150
152
  - test/helper.rb
@@ -164,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  segments:
166
168
  - 0
167
- hash: -121523023849342970
169
+ hash: 2782706298375828992
168
170
  required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  none: false
170
172
  requirements: