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
815 816 817 818 819 820 |
# File 'lib/content_data/content_data.rb', line 815 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.
718 719 720 721 722 723 724 725 726 727 |
# File 'lib/content_data/content_data.rb', line 718 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
729 730 731 732 733 734 735 736 737 |
# File 'lib/content_data/content_data.rb', line 729 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
763 764 765 766 767 768 769 770 771 772 |
# File 'lib/content_data/content_data.rb', line 763 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
807 808 809 810 811 812 |
# File 'lib/content_data/content_data.rb', line 807 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
796 797 798 799 800 801 802 803 804 805 |
# File 'lib/content_data/content_data.rb', line 796 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 |