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.
37 38 39 40 |
# File 'lib/mailer.rb', line 37 def initialize @options = {} @error_message = "" end |
Instance Attribute Details
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
18 19 20 |
# File 'lib/mailer.rb', line 18 def @error_message end |
Class Method Details
.create ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mailer.rb', line 20 def self.create this = instance this.clear setting_file_path = File.join(Narou.get_root_dir, SETTING_FILE) if File.exist?(setting_file_path) = YAML.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
42 43 44 |
# File 'lib/mailer.rb', line 42 def clear @options.clear end |
#extname(path) ⇒ Object
.kepub.epub を考慮する必要がある
72 73 74 75 76 77 78 |
# File 'lib/mailer.rb', line 72 def extname(path) if File.basename(path) =~ /\A[^.]+(.+)/ $1 else "" end end |
#options=(options) ⇒ Object
46 47 48 |
# File 'lib/mailer.rb', line 46 def () @options.merge!() end |
#send(id, message, attached_file_path = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/mailer.rb', line 50 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 |