kiss 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0
1
+ 1.0.1
data/lib/kiss/action.rb CHANGED
@@ -70,19 +70,19 @@ class Kiss
70
70
  def validate_arg(index, format, required = false)
71
71
  Kiss.validate_value(@args[index], format, required, "arg #{index}")
72
72
  end
73
-
73
+
74
74
  # Creates and invokes new Kiss::Mailer instance to send email message via sendmail.
75
- def sendmail(options)
76
- Kiss::Mailer.new.sendmail({
77
- :data => data
75
+ def sendmail(options = {})
76
+ send_email({
77
+ :engine => :sendmail
78
78
  }.merge(options))
79
79
  end
80
80
 
81
- # Creates and invokes new Kiss::Mailer instance to send email message via SMTP,
82
- # unless options specify :engine => :sendmail.
83
- def send_email(options)
84
- controller.new_email.send({
85
- :data => data
81
+ # Creates and invokes new Kiss::Mailer instance to send email message via SMTP.
82
+ def send_email(options = {})
83
+ Kiss::Mailer.new.send_email({
84
+ :data => data,
85
+ :controller => controller
86
86
  }.merge(options))
87
87
  end
88
88
 
data/lib/kiss/mailer.rb CHANGED
@@ -3,24 +3,26 @@ class Kiss
3
3
  class Mailer
4
4
  include Kiss::TemplateMethods
5
5
 
6
- # Creates new email message object.
7
- def initialize(controller,options = {})
8
- @controller = controller
9
- @options = {
10
- :engine => :sendmail
11
- }.merge(options)
12
-
13
- @data = {}
6
+ attr_accessor :controller
7
+
8
+ def merge_options(options = {})
9
+ @options.merge!(options)
10
+ @controller = options[:controller] || @controller
11
+ @data = options[:data] || @data
14
12
  end
15
13
 
16
- def controller
17
- @controller
14
+ # Creates new email message object.
15
+ def initialize(options = {})
16
+ @options = {}
17
+ @data = {}
18
+
19
+ merge_options(options) if options
18
20
  end
19
21
 
20
22
  # Renders email template to string, unless message option is
21
23
  # already set to a string value.
22
- def prepare_email_message(options = {})
23
- @options.merge!(options)
24
+ def prepare_email_message(options = nil)
25
+ merge_options(options) if options
24
26
 
25
27
  unless @options[:message].is_a?(String)
26
28
  if template_name = @options[:template]
@@ -39,16 +41,12 @@ class Kiss
39
41
  return @options[:message]
40
42
  end
41
43
 
42
- # Sets data to be passed to email template.
43
- def set(key,value)
44
- @data[key] = value
45
- end
46
-
47
44
  # Attempts to send message using SMTP, unless :engine option is set to
48
45
  # :sendmail.
49
- def send(options)
50
- @options.merge!(options)
51
- if options[:engine] == :sendmail
46
+ def send(options = nil)
47
+ merge_options(options) if options
48
+
49
+ if @options[:engine] == :sendmail
52
50
  return sendmail
53
51
  else
54
52
  return send_smtp
@@ -56,7 +54,9 @@ class Kiss
56
54
  end
57
55
 
58
56
  # Attempts to send message using /usr/sbin/sendmail.
59
- def sendmail(options = {})
57
+ def sendmail(options = nil)
58
+ merge_options(options) if options
59
+
60
60
  prepare_email_message(options)
61
61
 
62
62
  IO.popen(@options[:sendmail_path] || "/usr/sbin/sendmail -t","w") do |pipe|
@@ -65,7 +65,9 @@ class Kiss
65
65
  end
66
66
 
67
67
  # Attempts to send message using Net::SMTP.
68
- def send_smtp(options = {})
68
+ def send_smtp(options = nil)
69
+ merge_options(options) if options
70
+
69
71
  prepare_email_message(options)
70
72
 
71
73
  require 'net/smtp' unless defined?(Net::SMTP)
data/lib/kiss/model.rb CHANGED
@@ -50,7 +50,7 @@ class Kiss
50
50
  association_reflections[name]
51
51
  end
52
52
 
53
- include Kiss::KissAccessors
53
+ include Kiss::ControllerAccessors
54
54
  end
55
55
 
56
56
  def method_missing(meth)
data/lib/kiss.rb CHANGED
@@ -820,7 +820,9 @@ class Kiss
820
820
 
821
821
  # Returns new Kiss::Mailer object using specified options.
822
822
  def new_email(options = {})
823
- Kiss::Mailer.new(options)
823
+ mailer = Kiss::Mailer.new(options)
824
+ mailer.controller = self
825
+ mailer
824
826
  end
825
827
 
826
828
  # Kiss Model cache, used to invoke and store Kiss database models.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiss
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Van Ittersum