File tree 7 files changed +106
-1
lines changed
7 files changed +106
-1
lines changed Original file line number Diff line number Diff line change
1
+ #
2
+ # This file contains the default configuration for Hatter.
3
+
4
+ # Each setting is of the form: <key> = <value>
5
+
6
+ # Path to the root of the local maildir
7
+ maildir = /path/to/maildir
8
+
9
+ # The format of the maildir, e.g maildir or mbox
10
+ maildir_format = maildir
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ group :development, :test do
4
4
gem 'rspec'
5
5
gem 'pry'
6
6
gem 'rake'
7
+ gem 'mail'
8
+ gem 'rbcurse'
9
+ gem 'configtoolkit'
7
10
end
8
11
9
12
# Specify your gem's dependencies in hatter.gemspec
Original file line number Diff line number Diff line change 6
6
GEM
7
7
remote: http://rubygems.org/
8
8
specs:
9
+ assertions (1.4.1 )
9
10
coderay (1.0.8 )
11
+ configtoolkit (2.3.2 )
12
+ assertions (>= 1.0.0 )
13
+ relative (>= 1.0.0 )
10
14
diff-lcs (1.1.3 )
15
+ ffi (1.3.1 )
16
+ ffi (1.3.1-x86-mingw32 )
17
+ ffi-locale (1.0.1 )
18
+ ffi (>= 1.0.9 )
19
+ ffi-ncurses (0.4.0 )
20
+ ffi (>= 1.0.9 )
21
+ ffi-locale (>= 1.0.0 )
22
+ i18n (0.6.1 )
23
+ mail (2.5.3 )
24
+ i18n (>= 0.4.0 )
25
+ mime-types (~> 1.16 )
26
+ treetop (~> 1.4.8 )
11
27
method_source (0.8.1 )
28
+ mime-types (1.19 )
29
+ polyglot (0.3.3 )
12
30
pry (0.9.11.4 )
13
31
coderay (~> 1.0.5 )
14
32
method_source (~> 0.8 )
19
37
slop (~> 3.4 )
20
38
win32console (~> 1.3 )
21
39
rake (10.0.3 )
40
+ rbcurse (1.5.2 )
41
+ rbcurse-core (>= 0.0 )
42
+ rbcurse-extras (>= 0.0 )
43
+ rbcurse-core (0.0.3 )
44
+ ffi-ncurses (>= 0.4.0 )
45
+ rbcurse-extras (0.0.0 )
46
+ rbcurse-core (>= 0.0.3 )
47
+ relative (1.0.3 )
22
48
rspec (2.12.0 )
23
49
rspec-core (~> 2.12.0 )
24
50
rspec-expectations (~> 2.12.0 )
28
54
diff-lcs (~> 1.1.3 )
29
55
rspec-mocks (2.12.2 )
30
56
slop (3.4.3 )
57
+ treetop (1.4.12 )
58
+ polyglot
59
+ polyglot (>= 0.3.1 )
31
60
win32console (1.3.2-x86-mingw32 )
32
61
33
62
PLATFORMS
@@ -36,6 +65,9 @@ PLATFORMS
36
65
37
66
DEPENDENCIES
38
67
Hatter !
68
+ configtoolkit
69
+ mail
39
70
pry
40
71
rake
72
+ rbcurse
41
73
rspec
Original file line number Diff line number Diff line change
1
+ require 'configtoolkit'
2
+ require 'configtoolkit/keyvaluereader'
3
+
4
+ class Configuration < ConfigToolkit ::BaseConfig
5
+
6
+ # Reads a configuration from file.
7
+ #
8
+ # @param [String] configPath the path to a configuration file.
9
+ #
10
+ # @return [Configuration] with values loaded from file.
11
+ def self . from_file configPath
12
+ reader = ConfigToolkit ::KeyValueReader . new configPath
13
+ load reader
14
+ end
15
+
16
+ add_required_param ( :maildir , String )
17
+ add_required_param ( :maildir_format , String )
18
+ end
Original file line number Diff line number Diff line change
1
+
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+ require 'relative'
3
+ require 'configtoolkit/keyvaluereader'
4
+
5
+ describe 'Configuration' do
6
+
7
+ before :all do
8
+ @maildir_path = "/path/to/maildir"
9
+ CONFIG_FILE = File . expand_path_relative_to_caller ( "../.hatterrc" )
10
+ @maildir_format = "maildir"
11
+ @config = Configuration . new ( ) do |config |
12
+ config . maildir = @maildir_path
13
+ config . maildir_format = @maildir_format
14
+ end
15
+ end
16
+
17
+ it "contains all the required configuration settings" do
18
+ @config . maildir? . should be_true
19
+ @config . maildir_format? . should be_true
20
+ end
21
+
22
+ it "the settings have the correct values" do
23
+ @config . maildir . should eq @maildir_path
24
+ @config . maildir_format . should eq @maildir_format
25
+ end
26
+
27
+ it "reads the configuration values from file" do
28
+ config = Configuration . from_file CONFIG_FILE
29
+ config . maildir . should eq @maildir_path
30
+ config . maildir_format . should eq @maildir_format
31
+ end
32
+
33
+ it "barfs when required values are missing" do
34
+ config = File . read CONFIG_FILE
35
+ config . gsub! ( /maildir/ , 'asdf' )
36
+ File . open ( "invalid_config" , "w" ) { |file | file . write config }
37
+ expect { Configuration . from_file ( "invalid_config" ) } . to raise_error
38
+ FileUtils ::rm ( "invalid_config" )
39
+ end
40
+ end
Original file line number Diff line number Diff line change 1
1
require 'rspec'
2
2
3
- require './lib/hatter.rb'
3
+ require './lib/hatter.rb'
4
+ require './lib/configuration.rb'
You can’t perform that action at this time.
0 commit comments