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

project    - Name of the project to post to (e.g.
             project.idonethis.com)
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).

Returns a new Idid::Configuration instance

Raises:

  • (ArgumentError)


37
38
39
40
41
42
43
44
45
46
# File 'lib/idid/configuration.rb', line 37

def initialize options = {}
  options = options.merge(read_config) if read_config
  raise ArgumentError.new("Provide a project to use.") unless options['project']
  raise ArgumentError.new("Provide an email address.") unless options['email']
  raise ArgumentError.new("Provide a delivery method.") unless options['delivery']

  @project    = options['project']
  @email      = options['email']
  @delivery = options['delivery']
end

Instance Attribute Details

#deliveryObject

Public: Email delivery configuration



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

def delivery
  @delivery
end

#emailObject

Public: Email address String to use when sending mail.



20
21
22
# File 'lib/idid/configuration.rb', line 20

def email
  @email
end

#projectObject

Public: Name of the project to post to (e.g. project.idonethis.com)



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

def project
  @project
end

Class Method Details

.config_fileObject



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

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

.read_configObject



64
65
66
67
68
# File 'lib/idid/configuration.rb', line 64

def self.read_config
  if File.exist? config_file
    config = YAML.load_file config_file
  end
end

Instance Method Details

#read_configObject



60
61
62
# File 'lib/idid/configuration.rb', line 60

def read_config
  @config ||= self.class.read_config
end

#writeObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/idid/configuration.rb', line 48

def write
  config = {
    'project' => project,
    'email'   => email,
    'delivery' => delivery
  }

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