Class: ActiveFile::Base

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

Direct Known Subclasses

ActiveJSON::Base, ActiveYaml::Base

Constant Summary collapse

@@instance_lock =
Mutex.new

Class Method Summary collapse

Methods included from MultipleFiles

full_paths, multiple_files?, multiple_files?, set_filenames, use_multiple_files

Methods inherited from ActiveHash::Base

#[], #[]=, #_read_attribute, add_default_value, add_to_record_index, all, #attributes, auto_assign_fields, base_class, #cache_key, cache_key, composite_primary_key?, compute_type, configuration_for_custom_finder, create, create!, data, data=, define_custom_find_all_method, define_custom_find_method, define_getter_method, define_interrogator_method, define_setter_method, #destroyed?, empty?, #eql?, #errors, exists?, field, field_names, fields, has_query_constraints?, #hash, #id, #id=, #initialize, insert, mark_clean, mark_dirty, #marked_for_destruction?, method_missing, #new_record?, next_id, #persisted?, pluralize_table_names, polymorphic_name, primary_key, #readonly?, record_index, reset_record_index, respond_to?, #save, scope, the_meta_class, #to_param, transaction, #valid?, validate_field, validate_unique_id

Constructor Details

This class inherits a constructor from ActiveHash::Base

Class Method Details

.actual_root_pathObject



47
48
49
# File 'lib/active_file/base.rb', line 47

def actual_root_path
  root_path  || Dir.pwd
end

.all_in_processObject



59
60
61
62
# File 'lib/active_file/base.rb', line 59

def all_in_process
  return super if data_loaded
  @records || []
end

.delete_allObject



11
12
13
14
# File 'lib/active_file/base.rb', line 11

def delete_all
  self.data_loaded = true
  super
end

.extensionObject



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

def extension
  raise "Override Me"
end

.full_pathObject



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

def full_path
  actual_filename  = filename   || name.tableize
  File.join(actual_root_path, "#{actual_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



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

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

.set_filename(name) ⇒ Object



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

def set_filename(name)
  self.filename = name
end

.set_root_path(path) ⇒ Object



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

def set_root_path(path)
  self.root_path = path
end