Module: RubySync::Connectors::DbmAssociationTracking
- Defined in:
- lib/ruby_sync/connectors/dbm_association_tracking.rb
Instance Method Summary collapse
-
#associate(association, path) ⇒ Object
Store association for the given path.
- #association_key_for(context, path) ⇒ Object
-
#association_to_path_dbm_filename ⇒ Object
Stores paths indexed by association_context:association_key.
- #associations_for(path) ⇒ Object
- #path_for_association(association) ⇒ Object
-
#path_to_association_dbm_filename ⇒ Object
Stores association keys indexed by path:association_context.
- #remove_association(association) ⇒ Object
- #remove_associations ⇒ Object
Instance Method Details
#associate(association, path) ⇒ Object
Store association for the given path
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 25 def associate association, path YAML::DBM.open(path_to_association_dbm_filename) do |dbm| assocs = dbm[path.to_s] || {} assocs[association.context.to_s] = association.key.to_s dbm[path.to_s] = assocs end DBM.open(association_to_path_dbm_filename) do |dbm| dbm[association.to_s] = path end end |
#association_key_for(context, path) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 62 def association_key_for context, path YAML::DBM.open(path_to_association_dbm_filename) do |dbm| assocs = dbm[path.to_s] || {} assocs[context.to_s] end end |
#association_to_path_dbm_filename ⇒ Object
Stores paths indexed by association_context:association_key
80 81 82 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 80 def association_to_path_dbm_filename dbm_path + "_assoc_to_path" end |
#associations_for(path) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 43 def associations_for path YAML::DBM.open(path_to_association_dbm_filename) do |dbm| assocs = dbm[path.to_s] assocs.values end end |
#path_for_association(association) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 36 def path_for_association association is_vault? or return path_for_own_association_key(association.key) DBM.open(association_to_path_dbm_filename) do |dbm| dbm[association.to_s] end end |
#path_to_association_dbm_filename ⇒ Object
Stores association keys indexed by path:association_context
75 76 77 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 75 def path_to_association_dbm_filename dbm_path + "_path_to_assoc" end |
#remove_association(association) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 51 def remove_association association path = nil DBM.open(association_to_path_dbm_filename) do |dbm| return unless path =dbm.delete(association.to_s) end YAML::DBM.open(path_to_association_dbm_filename) do |dbm| assocs = dbm[path.to_s] assocs.delete(association.context) and dbm[path.to_s] = assocs end end |
#remove_associations ⇒ Object
69 70 71 |
# File 'lib/ruby_sync/connectors/dbm_association_tracking.rb', line 69 def remove_associations File.delete_if_exists(["#{association_to_path_dbm_filename}.db","#{path_to_association_dbm_filename}.db"]) end |