Class: RubySync::Connectors::XmlConnector

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

Instance Attribute Summary

Attributes inherited from BaseConnector

#is_vault, #name, #once_only

Class Method Summary collapse

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?, #initialize, #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, #perform_operations, #remove_association, #remove_associations, #remove_mirror, #start, #started, #stop, #stopped, #test_add, #test_delete, #test_modify

Methods included from Utilities

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

Constructor Details

This class inherits a constructor from RubySync::Connectors::BaseConnector

Class Method Details

.sample_configObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 77

def self.sample_config
      return "      #\n      # \"filename\" should be the full name of the file containing\n      # the xml representation of the synchronized content.\n      # You probably want to change this:\n      #\n      filename \"/tmp/rubysync.xml\"\n"
end

Instance Method Details

#[](id) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 62

def [](id)
  value = nil
  with_xml(:read_only=>true) do |content|
    value = content[id] && content[id][0]
  end
  value
end

#[]=(id, value) ⇒ Object



70
71
72
73
74
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 70

def []=(id, value)
  with_xml do |content|
    content[id] = value 
  end
end

#add(id, operations) ⇒ Object



40
41
42
43
44
45
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 40

def add id, operations
  with_xml do |content|
    content[id] = perform_operations(operations)
  end
  id
end

#delete(id) ⇒ Object



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

def delete id
  with_xml do |content|
    content.delete(id)
  end
  id
end

#each_entryObject



32
33
34
35
36
37
38
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 32

def each_entry
  with_xml(:read_only=>true) do |content|
    content.each do |entry|
      yield entry[0], entry[1][0]
    end
  end
end

#modify(id, operations) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/ruby_sync/connectors/xml_connector.rb', line 47

def modify id, operations
  with_xml do |content|
    existing = content[id] && content[id][0] || {}
    content[id] = perform_operations(operations, existing)
  end
  id
end