Class: Idid::Configuration
- Inherits:
-
Object
- Object
- Idid::Configuration
- Defined in:
- lib/idid/configuration.rb
Constant Summary collapse
- SMTP_DEFAULTS =
{ :address => 'smtp.gmail.com', :port => '587', :user_name => ENV['GMAIL_SMTP_USER'], :password => ENV['GMAIL_SMTP_PASSWORD'], :authentication => :plain, :enable_starttls_auto => true }
- EXIM_DEFAULTS =
{ :location => '/usr/bin/exim' }
Instance Attribute Summary collapse
-
#account_type ⇒ Object
Public: Account type for this user.
-
#delivery ⇒ Object
Public: Email delivery configuration.
-
#email ⇒ Object
Public: Email address String to use when sending mail.
-
#team ⇒ Object
Public: Name of the team to post to.
Class Method Summary collapse
Instance Method Summary collapse
-
#idonethis_email ⇒ Object
Public: The email address of IDoneThis to send your updates to.
-
#initialize(options = {}) ⇒ Configuration
constructor
Public: configuration to use with iDoneThis.
-
#personal_account? ⇒ Boolean
Public: Determines if current configuration belongs to a personal account.
- #read_config ⇒ Object
-
#team_account? ⇒ Boolean
Public: Determines if current configuration belongs to a team account.
- #write ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Public: configuration to use with iDoneThis
options - Hash with configuration options
email - Email address to use when sending mail.
delivery - Email delivery configuration Hash:
method - Symbol (:smtp|:sendmail|:exim)
options - Configuration Hash for the
delivery method (see:
https://github.com/mikel/mail).
team - Name of the team to post to (optional)
Returns a new Idid::Configuration instance
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/idid/configuration.rb', line 38 def initialize( = {}) = read_config.merge if read_config raise ArgumentError.new "Provide an account type." unless ['account_type'] raise ArgumentError.new "Provide a team to use." if ['account_type'] == 'team' && ['team'].nil? raise ArgumentError.new "Provide an email address." unless ['email'] raise ArgumentError.new "Provide a delivery method." unless ['delivery'] @account_type = ['account_type'] @team = ['team'] @email = ['email'] @delivery = ['delivery'] end |
Instance Attribute Details
#account_type ⇒ Object
Public: Account type for this user
18 19 20 |
# File 'lib/idid/configuration.rb', line 18 def account_type @account_type end |
#delivery ⇒ Object
Public: Email delivery configuration
24 25 26 |
# File 'lib/idid/configuration.rb', line 24 def delivery @delivery end |
#email ⇒ Object
Public: Email address String to use when sending mail.
22 23 24 |
# File 'lib/idid/configuration.rb', line 22 def email @email end |
#team ⇒ Object
Public: Name of the team to post to
20 21 22 |
# File 'lib/idid/configuration.rb', line 20 def team @team end |
Class Method Details
.config_file ⇒ Object
96 97 98 |
# File 'lib/idid/configuration.rb', line 96 def self.config_file File.join ENV['HOME'], '.idid.yml' end |
.read_config ⇒ Object
90 91 92 93 94 |
# File 'lib/idid/configuration.rb', line 90 def self.read_config if File.exist? config_file config = YAML.load_file config_file end end |
Instance Method Details
#idonethis_email ⇒ Object
Public: The email address of IDoneThis to send your updates to. This depends on whether you have a personal or a team account.
Returns the String with the right email address to use
55 56 57 |
# File 'lib/idid/configuration.rb', line 55 def idonethis_email personal_account? ? "[email protected]" : "#{team}@team.idonethis.com" end |
#personal_account? ⇒ Boolean
Public: Determines if current configuration belongs to a personal account
Returns boolean
62 63 64 |
# File 'lib/idid/configuration.rb', line 62 def personal_account? account_type == 'personal' end |
#read_config ⇒ Object
86 87 88 |
# File 'lib/idid/configuration.rb', line 86 def read_config @config ||= self.class.read_config end |
#team_account? ⇒ Boolean
Public: Determines if current configuration belongs to a team account
Returns boolean
69 70 71 |
# File 'lib/idid/configuration.rb', line 69 def team_account? account_type == 'team' end |
#write ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/idid/configuration.rb', line 73 def write config = { 'account_type' => account_type, 'team' => team, 'email' => email, 'delivery' => delivery } File.open(self.class.config_file, 'w') do |f| f.write config.to_yaml end end |