tg_config 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module TechnoGate
2
2
  class TgConfig
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
  PRE = ''
7
7
 
8
8
  def self.version
data/lib/tg_config.rb CHANGED
@@ -2,7 +2,7 @@ require "rubygems"
2
2
  require "bundler/setup"
3
3
 
4
4
  require "yaml"
5
- require "active_support/core_ext/hash/indifferent_access"
5
+ require "active_support/core_ext"
6
6
  require "tg_config/errors"
7
7
  require "tg_config/version"
8
8
 
@@ -23,6 +23,10 @@ module TechnoGate
23
23
  # @return mixed
24
24
  # @raise [Void]
25
25
  def [](config)
26
+ unless @config
27
+ check_config_file
28
+ @config = parse_config_file
29
+ end
26
30
  @config.send(:[], config)
27
31
  end
28
32
 
@@ -31,6 +35,10 @@ module TechnoGate
31
35
  # @param [String] config
32
36
  # @param [Mixed] Values
33
37
  def []=(config, value)
38
+ unless @config
39
+ check_config_file
40
+ @config = parse_config_file
41
+ end
34
42
  @config.send(:[]=, config, value)
35
43
  end
36
44
 
@@ -25,6 +25,10 @@ describe TgConfig do
25
25
  ::File.stubs(:open).with(config_path, 'w').yields(@file_handler)
26
26
  end
27
27
 
28
+ after(:each) do
29
+ subject.send(:instance_variable_set, :@config, nil)
30
+ end
31
+
28
32
  describe "#config_file" do
29
33
  it { should respond_to :config_file }
30
34
 
@@ -66,12 +70,16 @@ describe TgConfig do
66
70
  ::File.stubs(:readable?).with(config_path).returns(false)
67
71
 
68
72
  lambda { subject.send(:check_config_file) }.should raise_error TgConfig::NotReadableError
73
+
74
+ ::File.stubs(:readable?).with(config_path).returns(true)
69
75
  end
70
76
 
71
77
  it "should raise TgConfig::NotWritableError if config not readable" do
72
78
  ::File.stubs(:writable?).with(config_path).returns(false)
73
79
 
74
80
  lambda { subject.send(:check_config_file, true) }.should raise_error TgConfig::NotWritableError
81
+
82
+ ::File.stubs(:writable?).with(config_path).returns(true)
75
83
  end
76
84
 
77
85
  end
@@ -111,13 +119,23 @@ describe TgConfig do
111
119
  it "should return [:pathogen] for submodules" do
112
120
  subject[:submodules].should == [:pathogen]
113
121
  end
114
- end
115
122
 
116
- describe "#[]=" do
117
- after(:each) do
123
+ it "should call check_config_file if @config is nil" do
118
124
  subject.send(:instance_variable_set, :@config, nil)
125
+ subject.expects(:check_config_file).once
126
+
127
+ subject[:submodules]
119
128
  end
120
129
 
130
+ it "should call parse_config_file if @config is nil" do
131
+ subject.send(:instance_variable_set, :@config, nil)
132
+ subject.expects(:parse_config_file).returns(config.with_indifferent_access).once
133
+
134
+ subject[:submodules]
135
+ end
136
+ end
137
+
138
+ describe "#[]=" do
121
139
  it { should respond_to :[]= }
122
140
 
123
141
  it "should set the new config in @config" do
@@ -125,6 +143,20 @@ describe TgConfig do
125
143
  subject.send(:instance_variable_get, :@config)[:submodules].should ==
126
144
  [:pathogen, :github]
127
145
  end
146
+
147
+ it "should call check_config_file if @config is nil" do
148
+ subject.send(:instance_variable_set, :@config, nil)
149
+ subject.expects(:check_config_file).once
150
+
151
+ subject[:submodules] = {}
152
+ end
153
+
154
+ it "should call parse_config_file if @config is nil" do
155
+ subject.send(:instance_variable_set, :@config, nil)
156
+ subject.expects(:parse_config_file).returns(config.with_indifferent_access).once
157
+
158
+ subject[:submodules] = {}
159
+ end
128
160
  end
129
161
 
130
162
  describe "#write_config_file" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tg_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-12 00:00:00.000000000 Z
12
+ date: 2011-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &22579640 !ruby/object:Gem::Requirement
16
+ requirement: &22629900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22579640
24
+ version_requirements: *22629900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &22576540 !ruby/object:Gem::Requirement
27
+ requirement: &22627500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22576540
35
+ version_requirements: *22627500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &22592200 !ruby/object:Gem::Requirement
38
+ requirement: &22623980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *22592200
46
+ version_requirements: *22623980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &22620700 !ruby/object:Gem::Requirement
49
+ requirement: &22645260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.8.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *22620700
57
+ version_requirements: *22645260
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-bundler
60
- requirement: &22618820 !ruby/object:Gem::Requirement
60
+ requirement: &22643100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.1.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *22618820
68
+ version_requirements: *22643100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
- requirement: &22615960 !ruby/object:Gem::Requirement
71
+ requirement: &22641460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.5
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *22615960
79
+ version_requirements: *22641460
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: yard
82
- requirement: &22637200 !ruby/object:Gem::Requirement
82
+ requirement: &22639520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.7.2
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *22637200
90
+ version_requirements: *22639520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &22634280 !ruby/object:Gem::Requirement
93
+ requirement: &22662060 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 2.6.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *22634280
101
+ version_requirements: *22662060
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: mocha
104
- requirement: &22646980 !ruby/object:Gem::Requirement
104
+ requirement: &22659880 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.10.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *22646980
112
+ version_requirements: *22659880
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: pry
115
- requirement: &22646220 !ruby/object:Gem::Requirement
115
+ requirement: &22657740 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ~>
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: 0.9.6.2
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *22646220
123
+ version_requirements: *22657740
124
124
  description: A simple YAML configuration reader and writer
125
125
  email:
126
126
  - wael.nasreddine@gmail.com
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  version: '0'
161
161
  segments:
162
162
  - 0
163
- hash: 4005192496713745643
163
+ hash: 4110832875937430227
164
164
  requirements: []
165
165
  rubyforge_project:
166
166
  rubygems_version: 1.8.11