Class: Idid::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  options = read_config.merge options if read_config
  raise ArgumentError.new "Provide an account type." unless options['account_type']
  raise ArgumentError.new "Provide a team to use." if options['account_type'] == 'team' && options['team'].nil?
  raise ArgumentError.new "Provide an email address." unless options['email']
  raise ArgumentError.new "Provide a delivery method." unless options['delivery']

  @account_type = options['account_type']
  @team = options['team']
  @email = options['email']
  @delivery = options['delivery']
end

Instance Attribute Details

#account_typeObject

Public: Account type for this user



18
19
20
# File 'lib/idid/configuration.rb', line 18

def 
  @account_type
end

#deliveryObject

Public: Email delivery configuration



24
25
26
# File 'lib/idid/configuration.rb', line 24

def delivery
  @delivery
end

#emailObject

Public: Email address String to use when sending mail.



22
23
24
# File 'lib/idid/configuration.rb', line 22

def email
  @email
end

#teamObject

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_fileObject



96
97
98
# File 'lib/idid/configuration.rb', line 96

def self.config_file
  File.join ENV['HOME'], '.idid.yml'
end

.read_configObject



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_emailObject

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/idid/configuration.rb', line 62

def personal_account?
   == 'personal'
end

#read_configObject



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

Returns:

  • (Boolean)


69
70
71
# File 'lib/idid/configuration.rb', line 69

def team_account?
   == 'team'
end

#writeObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/idid/configuration.rb', line 73

def write
  config = {
    'account_type' => ,
    'team' => team,
    'email'   => email,
    'delivery' => delivery
  }

  File.open(self.class.config_file, 'w') do |f|
    f.write config.to_yaml
  end
end