Class: RubySync::Connectors::MemoryConnector

Inherits:
BaseConnector show all
Defined in:
lib/ruby_sync/connectors/memory_connector.rb

Instance Attribute Summary

Attributes inherited from BaseConnector

#is_vault, #name, #once_only, #pipeline

Instance Method Summary collapse

Methods inherited from BaseConnector

#associate, #association_context, #association_for, #association_key_for, #association_to_path_dbm_filename, #associations_for, #can_act_as_vault?, class_for, class_name_for, #clean, #create_operations_for, #dbm_path, #digest, #each_change, #entry_for_own_association_key, fields, #find_associated, #has_entry_for_key?, #is_delete_echo?, #is_echo?, #is_vault?, #mirror_dbm_filename, #own_association_key_for, #path_for_association, #path_for_own_association_key, #path_to_association_dbm_filename, #remove_association, #remove_associations, #remove_mirror, sample_config, #start, #started, #stop, #stopped, #sync_started, #sync_stopped, #test_add, #test_delete, #test_modify

Methods included from Utilities

#as_array, #base_path, #call_if_exists, #connector_called, #effective_operations, #ensure_dir_exists, #find_base_path, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #perform_operations, #pipeline_called, #set_preference, #something_called, #with_rescue

Constructor Details

#initialize(options) ⇒ MemoryConnector



31
32
33
34
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 31

def initialize options
  super
  @data = {}
end

Instance Method Details

#[](key) ⇒ Object



64
65
66
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 64

def [](key)
  @data[normalize(key)]
end

#[]=(key, value) ⇒ Object



68
69
70
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 68

def []=(key, value)
  @data[normalize(key)] = value
end

#add(id, operations) ⇒ Object

Raises:

  • (Exception)


36
37
38
39
40
41
42
43
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 36

def add id, operations
  id = normalize id
  raise Exception.new("Item already exists") if @data[id]
  log.debug "Adding new record with key '#{id}'"
  @data[id] = perform_operations operations
  association_key = (is_vault?)? nil : [nil, own_association_key_for(id)]
  return id
end

#delete(id) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 53

def delete id
  id = normalize id
  unless @data[id]
     log.warn "Can't delete non-existent item '#{id}'"
     return
   end
  @data.delete id
end

#each_entryObject



24
25
26
27
28
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 24

def each_entry
  @data.each do |key, entry|
    yield key, entry
  end
end

#modify(id, operations) ⇒ Object

Raises:

  • (Exception)


45
46
47
48
49
50
# File 'lib/ruby_sync/connectors/memory_connector.rb', line 45

def modify id, operations
  id = normalize id
  raise Exception.new("Attempting to modify non-existent record '#{id}'") unless @data[id]
  perform_operations operations, @data[id]
  return id
end