Class: Mailer
Defined Under Namespace
Classes: SettingNotFound, SettingUncompleteError
Constant Summary collapse
- SETTING_FILE =
"mail_setting.yaml"
Instance Attribute Summary collapse
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#extname(path) ⇒ Object
.kepub.epub を考慮する必要がある.
-
#initialize ⇒ Mailer
constructor
A new instance of Mailer.
- #options=(options) ⇒ Object
- #send(id, message, attached_file_path = nil) ⇒ Object
Constructor Details
#initialize ⇒ Mailer
Returns a new instance of Mailer.
38 39 40 41 |
# File 'lib/mailer.rb', line 38 def initialize @options = {} @error_message = "" end |
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
19 20 21 |
# File 'lib/mailer.rb', line 19 def @error_message end |
Class Method Details
.create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mailer.rb', line 21 def self.create this = instance this.clear setting_file_path = File.join(Narou.root_dir, SETTING_FILE) if File.exist?(setting_file_path) = YAML.unsafe_load_file(setting_file_path) unless .delete(:complete) raise SettingUncompleteError, "設定ファイルの書き換えが終了していないようです。\n" + "設定ファイルは #{setting_file_path} にあります" end this. = else raise SettingNotFound end this end |
Instance Method Details
#clear ⇒ Object
43 44 45 |
# File 'lib/mailer.rb', line 43 def clear @options.clear end |
#extname(path) ⇒ Object
.kepub.epub を考慮する必要がある
73 74 75 76 77 78 79 |
# File 'lib/mailer.rb', line 73 def extname(path) if File.basename(path) =~ /\A[^.]+(.+)/ $1 else "" end end |
#options=(options) ⇒ Object
47 48 49 |
# File 'lib/mailer.rb', line 47 def () @options.merge!() end |
#send(id, message, attached_file_path = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mailer.rb', line 51 def send(id, , attached_file_path = nil) gem "mail", "2.6.6" require "pony" @error_message = "" params = @options.dup params[:body] = params[:charset] = "UTF-8" params[:text_part_charset] = "UTF-8" if attached_file_path basename = "#{id}#{extname(attached_file_path)}" params[:attachments] = { basename => File.binread(attached_file_path) } end begin Pony.mail(params) rescue StandardError => e @error_message = e. return false end true end |