Class: PostDB::MailLocation
- Inherits:
-
Object
- Object
- PostDB::MailLocation
- Defined in:
- lib/postdb/mail_location.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #get_path(username, domain, home_dir = nil) ⇒ Object
-
#initialize(location) ⇒ MailLocation
constructor
A new instance of MailLocation.
Constructor Details
#initialize(location) ⇒ MailLocation
Returns a new instance of MailLocation.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/postdb/mail_location.rb', line 7 def initialize(location) unless location =~ /^[A-Za-z0-9]+:(.*)$/ raise PostDB::MailLocationError.new(:malformed_location) end components = location.split(':') @type = components[0].to_sym @path = components[1] begin @components = Hash[*components[2..-1].map { |c| c.split('=') }.flatten] rescue => e raise PostDB::MailLocationError.new(:malformed_location) end end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
5 6 7 |
# File 'lib/postdb/mail_location.rb', line 5 def components @components end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/postdb/mail_location.rb', line 4 def path @path end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/postdb/mail_location.rb', line 3 def type @type end |
Instance Method Details
#get_path(username, domain, home_dir = nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/postdb/mail_location.rb', line 24 def get_path(username, domain, home_dir = nil) path = @path.dup path.gsub!('%u', username) path.gsub!('%n', username.split('@')[0]) path.gsub!('%d', domain) path.gsub!('%h', home_dir) if home_dir path end |