Class: Checkm::Manifest
- Inherits:
-
Object
- Object
- Checkm::Manifest
- Defined in:
- lib/checkm/manifest.rb
Constant Summary collapse
- BASE_FIELDS =
['sourcefileorurl', 'alg', 'digest', 'length', 'modtime', 'targetfileorurl']
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#eof ⇒ Object
readonly
Returns the value of attribute eof.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #add(path_or_entry, args = {}) ⇒ Object (also: #<<)
-
#initialize(str_io_or_file = '', args = {}) ⇒ Manifest
constructor
A new instance of Manifest.
- #remove(path_or_entry) ⇒ Object (also: #-)
- #save ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #version ⇒ Object
Constructor Details
#initialize(str_io_or_file = '', args = {}) ⇒ Manifest
Returns a new instance of Manifest.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/checkm/manifest.rb', line 12 def initialize str_io_or_file = '', args = {} @source = str_io_or_file @args = args @entries = [] @eof = args[:eof] @version = args[:version] @fields = args[:fields] @path = args[:path] @path ||= Dir.pwd parse_lines(@source) end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
10 11 12 |
# File 'lib/checkm/manifest.rb', line 10 def entries @entries end |
#eof ⇒ Object (readonly)
Returns the value of attribute eof.
6 7 8 |
# File 'lib/checkm/manifest.rb', line 6 def eof @eof end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
8 9 10 |
# File 'lib/checkm/manifest.rb', line 8 def fields @fields end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/checkm/manifest.rb', line 9 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
5 6 7 |
# File 'lib/checkm/manifest.rb', line 5 def source @source end |
Instance Method Details
#add(path_or_entry, args = {}) ⇒ Object Also known as: <<
40 41 42 43 44 |
# File 'lib/checkm/manifest.rb', line 40 def add path_or_entry, args = {} args[:options] ||= @entries << Checkm::Entry.create(path_or_entry, args) end |
#remove(path_or_entry) ⇒ Object Also known as: -
48 49 50 51 52 53 54 |
# File 'lib/checkm/manifest.rb', line 48 def remove path_or_entry path = path_or_entry.path if path_or_entry.respond_to? :path path ||= path_or_entry[0] if path_or_entry.is_a? Entry or path_or_entry.is_a? Array path ||= path_or_entry @entries.reject! { |x| x[0] =~ /^@?#{path}/ } end |
#save ⇒ Object
71 72 73 74 75 |
# File 'lib/checkm/manifest.rb', line 71 def save raise unless @source.is_a? File File.open(@source.path, 'w') { |f| f.write(self.to_s) } end |
#to_hash ⇒ Object
77 78 79 |
# File 'lib/checkm/manifest.rb', line 77 def to_hash Hash[*@entries.map { |x| [x.sourcefileorurl, x] }.flatten] end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/checkm/manifest.rb', line 58 def to_s lines = [] lines << "#%checkm_#{version}" lines << "#%fields | #{ @fields.join(" | ") }" if @fields lines += entries.map(&:to_s) lines << '#%eof' if eof lines.join("\n") end |
#valid? ⇒ Boolean
35 36 37 38 |
# File 'lib/checkm/manifest.rb', line 35 def valid? return true if @entries.empty? not @entries.map { |e| e.valid? }.any? { |b| b == false } end |
#version ⇒ Object
27 28 29 |
# File 'lib/checkm/manifest.rb', line 27 def version @version || "0.7" end |