zilkey-active_hash 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -1
- data/VERSION +1 -1
- data/active_hash.gemspec +1 -1
- data/lib/active_file/base.rb +7 -2
- data/lib/active_hash/base.rb +1 -1
- data/spec/active_file/base_spec.rb +19 -1
- data/spec/active_hash/base_spec.rb +5 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
|
|
6
6
|
2009-07-24
|
|
7
7
|
- ActiveFile no longer reloads files by default
|
|
8
|
-
- Added ActiveFile.reload_active_file= so you can cause ActiveFile to reload
|
|
8
|
+
- Added ActiveFile.reload_active_file= so you can cause ActiveFile to reload
|
|
9
|
+
- Setting data to nil correctly causes .all to return an empty array
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.4.0
|
data/active_hash.gemspec
CHANGED
data/lib/active_file/base.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module ActiveFile
|
|
2
2
|
|
|
3
3
|
class Base < ActiveHash::Base
|
|
4
|
-
class_inheritable_accessor :filename, :root_path, :cached_mtime, :reload_active_file
|
|
4
|
+
class_inheritable_accessor :filename, :root_path, :cached_mtime, :reload_active_file, :data_has_been_set
|
|
5
5
|
|
|
6
6
|
class << self
|
|
7
7
|
def all
|
|
@@ -15,6 +15,11 @@ module ActiveFile
|
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def data=(array_of_hashes)
|
|
19
|
+
write_inheritable_attribute :data_has_been_set, true
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
|
|
18
23
|
protected :reload
|
|
19
24
|
|
|
20
25
|
def set_filename(name)
|
|
@@ -36,7 +41,7 @@ module ActiveFile
|
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
def should_reload?
|
|
39
|
-
return false if read_inheritable_attribute(:
|
|
44
|
+
return false if read_inheritable_attribute(:data_has_been_set) && ! read_inheritable_attribute(:reload_active_file)
|
|
40
45
|
return false if (mtime = File.mtime(full_path)) == read_inheritable_attribute(:cached_mtime)
|
|
41
46
|
|
|
42
47
|
write_inheritable_attribute :cached_mtime, mtime
|
data/lib/active_hash/base.rb
CHANGED
|
@@ -204,7 +204,7 @@ describe ActiveFile::Base do
|
|
|
204
204
|
Country.all
|
|
205
205
|
end
|
|
206
206
|
|
|
207
|
-
it "does not fetch data if data has been set" do
|
|
207
|
+
it "does not fetch data if data has been set to non-nil" do
|
|
208
208
|
class Country < ActiveFile::Base
|
|
209
209
|
class << self
|
|
210
210
|
def extension
|
|
@@ -221,6 +221,24 @@ describe ActiveFile::Base do
|
|
|
221
221
|
Country.data = [{:foo => :bar}]
|
|
222
222
|
Country.all
|
|
223
223
|
end
|
|
224
|
+
|
|
225
|
+
it "does not fetch data if data has been set to nil" do
|
|
226
|
+
class Country < ActiveFile::Base
|
|
227
|
+
class << self
|
|
228
|
+
def extension
|
|
229
|
+
"myfile"
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def load_file
|
|
233
|
+
MyClass.load_file(full_path)
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
MyClass.should_not_receive(:load_file)
|
|
239
|
+
Country.data = nil
|
|
240
|
+
Country.all
|
|
241
|
+
end
|
|
224
242
|
end
|
|
225
243
|
end
|
|
226
244
|
|
|
@@ -67,6 +67,11 @@ describe ActiveHash, "Base" do
|
|
|
67
67
|
]
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
it "returns an empty array if data is nil" do
|
|
71
|
+
Country.data = nil
|
|
72
|
+
Country.all.should be_empty
|
|
73
|
+
end
|
|
74
|
+
|
|
70
75
|
it "returns all data as inflated objects" do
|
|
71
76
|
Country.all.all?{|country| country.should be_kind_of(Country)}
|
|
72
77
|
end
|