Module: ContentData
- Defined in:
- lib/content_data.rb,
lib/content_data/version.rb,
lib/content_data/content_data.rb
Overview
Data structure for an abstract layer over files. Each binary sequence is a content, each file is content instance.
Defined Under Namespace
Classes: ContentData
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
-
.intersect(a, b) ⇒ Object
returns the common content in both a and b.
-
.merge(a, b) ⇒ Object
merges content data a and content data b to a new content data and returns it.
- .merge_override_b(a, b) ⇒ Object
-
.remove(a, b) ⇒ Object
B - A : Remove contents of A from B and return the new content data.
- .remove_directory(content_data, dir_to_remove, server_to_remove) ⇒ Object
-
.remove_instances(a, b) ⇒ Object
B - A : Remove instances of A content from B content data B and return the new content data.
Class Method Details
.intersect(a, b) ⇒ Object
returns the common content in both a and b
743 744 745 746 747 748 |
# File 'lib/content_data/content_data.rb', line 743 def self.intersect(a, b) return nil if a.nil? return nil if b.nil? b_minus_a = remove(a, b) b_minus_b_minus_a = remove(b_minus_a, b) end |
.merge(a, b) ⇒ Object
merges content data a and content data b to a new content data and returns it.
646 647 648 649 650 651 652 653 654 655 |
# File 'lib/content_data/content_data.rb', line 646 def self.merge(a, b) return ContentData.new(a) if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # Add A instances to content data c a.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| c.add_instance(checksum, size, server, path, instance_mod_time) } c end |
.merge_override_b(a, b) ⇒ Object
657 658 659 660 661 662 663 664 665 |
# File 'lib/content_data/content_data.rb', line 657 def self.merge_override_b(a, b) return ContentData.new(a) if b.nil? return ContentData.new(b) if a.nil? # Add A instances to content data B a.each_instance { |checksum, size, content_mod_time, instance_mod_time, server, path| b.add_instance(checksum, size, server, path, instance_mod_time) } b end |
.remove(a, b) ⇒ Object
B - A : Remove contents of A from B and return the new content data. instances are ignored e.g A db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
B db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
Instance_4
Content_3 ->
Instance_5
B-A db:
Content_3 ->
Instance_5
691 692 693 694 695 696 697 698 699 700 |
# File 'lib/content_data/content_data.rb', line 691 def self.remove(a, b) return nil if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # create new cloned content C from B # remove contents of A from newly cloned content A a.each_content { |checksum, size, content_mod_time| c.remove_content(checksum) } c end |
.remove_directory(content_data, dir_to_remove, server_to_remove) ⇒ Object
735 736 737 738 739 740 |
# File 'lib/content_data/content_data.rb', line 735 def self.remove_directory(content_data, dir_to_remove, server_to_remove) return nil if content_data.nil? result_content_data = ContentData.new(content_data) # clone from content_data result_content_data.remove_directory(dir_to_remove, server_to_remove) result_content_data end |
.remove_instances(a, b) ⇒ Object
B - A : Remove instances of A content from B content data B and return the new content data. If all instances are removed then the content record itself will be removed e.g A db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
B db:
Content_1 ->
Instance_1
Instance_2
Content_2 ->
Instance_3
Instance_4
B-A db:
Content_2 ->
Instance_4
724 725 726 727 728 729 730 731 732 733 |
# File 'lib/content_data/content_data.rb', line 724 def self.remove_instances(a, b) return nil if b.nil? return ContentData.new(b) if a.nil? c = ContentData.new(b) # create new cloned content C from B # remove contents of A from newly cloned content A a.each_instance { |_, _, _, _, server, path| c.remove_instance(server, path) } c end |