Module: Hybag::Baggable

Defined in:
lib/hybag/baggable.rb

Instance Method Summary collapse

Instance Method Details

#bagObject


18
19
20
21
# File 'lib/hybag/baggable.rb', line 18

def bag
  @bag = nil if @bag && @bag.bag_dir != bag_path
  @bag ||= BagIt::Bag.new(bag_path)
end

#bag_pathObject


14
15
16
# File 'lib/hybag/baggable.rb', line 14

def bag_path
  @bag_path ||= generate_bag_path
end

#baggable?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/hybag/baggable.rb', line 23

def baggable?
  true
end

#delete_bagObject


27
28
29
30
31
32
# File 'lib/hybag/baggable.rb', line 27

def delete_bag
  if(File.directory? bag_path)
    FileUtils.rm_r(bag_path, :force => true)
    @bag = nil
  end
end

#write_bag(path = '') ⇒ BagIt::Bag

Returns The bag that was created on the filesystem.

Returns:

  • (BagIt::Bag)

    The bag that was created on the filesystem.


4
5
6
7
8
9
10
11
12
# File 'lib/hybag/baggable.rb', line 4

def write_bag(path='')
  @bag_path = generate_bag_path(path)
  Hybag::Validator.new(self).validate!
  # Delete currently existing bag
  delete_bag
  # Make and write the bag
  FileUtils.mkdir_p bag_path
  Hybag::BagWriter.new(self).write!
end