Class: ActiveFile::Base

Inherits:
ActiveHash::Base show all
Defined in:
lib/active_file/base.rb

Direct Known Subclasses

ActiveYaml::Base

Instance Attribute Summary

Attributes inherited from ActiveHash::Base

#attributes

Class Method Summary collapse

Methods inherited from ActiveHash::Base

#[], #[]=, auto_assign_fields, base_class, #cache_key, configuration_for_custom_finder, count, create, create!, data=, define_custom_find_all_method, define_custom_find_method, define_getter_method, define_interrogator_method, define_setter_method, #destroyed?, #eql?, #errors, field, field_names, fields, find, find_by_id, has_instance_method?, has_singleton_method?, #hash, #id, #id=, #initialize, insert, mark_clean, mark_dirty, #marked_for_destruction?, method_missing, #new_record?, next_id, #persisted?, #readonly?, respond_to?, #save, the_meta_class, #to_param, transaction, #valid?, validate_field

Constructor Details

This class inherits a constructor from ActiveHash::Base

Class Method Details

.all(options = {}) ⇒ Object



8
9
10
11
# File 'lib/active_file/base.rb', line 8

def all(options={})
  reload unless data_loaded
  super
end

.delete_allObject



13
14
15
16
# File 'lib/active_file/base.rb', line 13

def delete_all
  self.data_loaded = true
  super
end

.extensionObject



43
44
45
# File 'lib/active_file/base.rb', line 43

def extension
  raise "Override Me"
end

.full_pathObject



37
38
39
40
41
# File 'lib/active_file/base.rb', line 37

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_fileObject



33
34
35
# File 'lib/active_file/base.rb', line 33

def load_file
  raise "Override Me"
end

.reload(force = false) ⇒ Object



18
19
20
21
22
23
# File 'lib/active_file/base.rb', line 18

def reload(force = false)
  return if !self.dirty && !force && self.data_loaded
  self.data_loaded = true
  self.data = load_file
  mark_clean
end

.set_filename(name) ⇒ Object



25
26
27
# File 'lib/active_file/base.rb', line 25

def set_filename(name)
  write_inheritable_attribute :filename, name
end

.set_root_path(path) ⇒ Object



29
30
31
# File 'lib/active_file/base.rb', line 29

def set_root_path(path)
  write_inheritable_attribute :root_path, path
end