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
749 750 751 752 753 754 |
# File 'lib/content_data/content_data.rb', line 749 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.
652 653 654 655 656 657 658 659 660 661 |
# File 'lib/content_data/content_data.rb', line 652 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
663 664 665 666 667 668 669 670 671 |
# File 'lib/content_data/content_data.rb', line 663 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
697 698 699 700 701 702 703 704 705 706 |
# File 'lib/content_data/content_data.rb', line 697 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
741 742 743 744 745 746 |
# File 'lib/content_data/content_data.rb', line 741 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
730 731 732 733 734 735 736 737 738 739 |
# File 'lib/content_data/content_data.rb', line 730 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 |