Class: RhetButler::FileLoading

Inherits:
Object
  • Object
show all
Defined in:
lib/rhet-butler/file-loading.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_set) ⇒ FileLoading

Returns a new instance of FileLoading.



5
6
7
8
# File 'lib/rhet-butler/file-loading.rb', line 5

def initialize(file_set)
  @file_set = file_set
  @loaded_paths = {}
end

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set.



9
10
11
# File 'lib/rhet-butler/file-loading.rb', line 9

def file_set
  @file_set
end

#loaded_pathsObject (readonly)

Returns the value of attribute loaded_paths.



9
10
11
# File 'lib/rhet-butler/file-loading.rb', line 9

def loaded_paths
  @loaded_paths
end

Instance Method Details

#initialize_copy(other) ⇒ Object



11
12
13
14
# File 'lib/rhet-butler/file-loading.rb', line 11

def initialize_copy(other)
  @file_set = other.file_set
  @loaded_paths = other.loaded_paths.dup
end

#load_file(rel_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rhet-butler/file-loading.rb', line 16

def load_file(rel_path)
  file = @file_set.find(rel_path)

  if @loaded_paths.has_key?(file.full_path)
    raise "Circular inclusion of slides: >> #{file.full_path} << #{@loaded_paths.keys.inspect}"
  else
    @loaded_paths[file.full_path] = true
  end

  begin
    return YAML.load_stream(file.contents).flatten
  rescue => ex
    puts "While processing `#{file.full_path}`"
    puts "  #{ex.class}: #{ex.message}"
    raise
  end
end