Class: ActiveFile::Base
Instance Attribute Summary
#attributes
Class Method Summary
collapse
auto_assign_fields, configuration_for_custom_finder, count, define_custom_find_all_method, define_custom_find_method, define_getter_method, define_interrogator_method, #eql?, field, fields, find, find_by_id, #hash, #id, #initialize, method_missing, #new_record?, #readonly?, respond_to?, #to_param
Class Method Details
.all ⇒ Object
7
8
9
10
|
# File 'lib/active_file/base.rb', line 7
def all
reload
super
end
|
.data=(array_of_hashes) ⇒ Object
18
19
20
21
|
# File 'lib/active_file/base.rb', line 18
def data=(array_of_hashes)
write_inheritable_attribute :data_has_been_set, true
super
end
|
.extension ⇒ Object
51
52
53
|
# File 'lib/active_file/base.rb', line 51
def extension
raise "Override Me"
end
|
.full_path ⇒ Object
35
36
37
38
39
|
# File 'lib/active_file/base.rb', line 35
def full_path
root_path = read_inheritable_attribute(:root_path) || Dir.pwd
filename = read_inheritable_attribute(:filename) || name.tableize
File.join(root_path, "#{filename}.#{extension}")
end
|
.load_file ⇒ Object
31
32
33
|
# File 'lib/active_file/base.rb', line 31
def load_file
raise "Override Me"
end
|
.reload(force = false) ⇒ Object
12
13
14
15
16
|
# File 'lib/active_file/base.rb', line 12
def reload(force = false)
if force || should_reload?
self.data = load_file
end
end
|
.set_filename(name) ⇒ Object
23
24
25
|
# File 'lib/active_file/base.rb', line 23
def set_filename(name)
write_inheritable_attribute :filename, name
end
|
.set_root_path(path) ⇒ Object
27
28
29
|
# File 'lib/active_file/base.rb', line 27
def set_root_path(path)
write_inheritable_attribute :root_path, path
end
|
.should_reload? ⇒ Boolean
41
42
43
44
45
46
47
|
# File 'lib/active_file/base.rb', line 41
def should_reload?
return false if read_inheritable_attribute(:data_has_been_set) && ! read_inheritable_attribute(:reload_active_file)
return false if (mtime = File.mtime(full_path)) == read_inheritable_attribute(:cached_mtime)
write_inheritable_attribute :cached_mtime, mtime
true
end
|