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 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.3.0
1
+ 0.4.0
data/active_hash.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{active_hash}
5
- s.version = "0.3.0"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jeff Dean", "Mike Dalessio"]
@@ -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(:data) && ! read_inheritable_attribute(:reload_active_file)
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
@@ -10,7 +10,7 @@ module ActiveHash
10
10
 
11
11
  def all
12
12
  unless @records
13
- records = read_inheritable_attribute(:data)
13
+ records = read_inheritable_attribute(:data) || []
14
14
  @records = records.collect {|hash| new(hash)}
15
15
  auto_assign_fields( records )
16
16
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zilkey-active_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dean