t 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/t/rcfile.rb +5 -6
- data/lib/t/version.rb +1 -1
- data/spec/rcfile_spec.rb +3 -3
- metadata +1 -1
data/lib/t/rcfile.rb
CHANGED
@@ -2,14 +2,13 @@ require 'singleton'
|
|
2
2
|
|
3
3
|
module T
|
4
4
|
class RCFile
|
5
|
-
FILE_NAME = '.trc'
|
6
|
-
attr_reader :path
|
7
|
-
|
8
5
|
include Singleton
|
6
|
+
attr_reader :path
|
7
|
+
FILE_NAME = '.trc'
|
9
8
|
|
10
9
|
def initialize
|
11
10
|
@path = File.join(File.expand_path("~"), FILE_NAME)
|
12
|
-
@data =
|
11
|
+
@data = load_file
|
13
12
|
end
|
14
13
|
|
15
14
|
def [](username)
|
@@ -59,7 +58,7 @@ module T
|
|
59
58
|
@data == default_structure
|
60
59
|
end
|
61
60
|
|
62
|
-
def
|
61
|
+
def load_file
|
63
62
|
require 'yaml'
|
64
63
|
YAML.load_file(@path)
|
65
64
|
rescue Errno::ENOENT
|
@@ -68,7 +67,7 @@ module T
|
|
68
67
|
|
69
68
|
def path=(path)
|
70
69
|
@path = path
|
71
|
-
@data =
|
70
|
+
@data = load_file
|
72
71
|
@path
|
73
72
|
end
|
74
73
|
|
data/lib/t/version.rb
CHANGED
data/spec/rcfile_spec.rb
CHANGED
@@ -160,19 +160,19 @@ describe T::RCFile do
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
-
describe '#
|
163
|
+
describe '#load_file' do
|
164
164
|
context 'when file exists at path' do
|
165
165
|
it 'should load data from file' do
|
166
166
|
rcfile = T::RCFile.instance
|
167
167
|
rcfile.path = fixture_path + "/.trc"
|
168
|
-
rcfile.
|
168
|
+
rcfile.load_file['profiles']['testcli']['abc123']['username'].should == 'testcli'
|
169
169
|
end
|
170
170
|
end
|
171
171
|
context 'when file does not exist at path' do
|
172
172
|
it 'should load default structure' do
|
173
173
|
rcfile = T::RCFile.instance
|
174
174
|
rcfile.path = File.expand_path('../fixtures/foo', __FILE__)
|
175
|
-
rcfile.
|
175
|
+
rcfile.load_file.keys.sort.should == ['configuration', 'profiles']
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|