Module: Exercise::DigestMethods

Included in:
RenderMethods
Defined in:
lib/commands/exercise/render_methods.rb

Instance Method Summary collapse

Instance Method Details

#digest(path:, digest_component:, excludes: []) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/commands/exercise/render_methods.rb', line 6

def digest(path:, digest_component:, excludes: [])
  excludes = paths(*excludes)

  files = files(path).sort.reject do |f|
    excludes.include?(f) || ignored?(path, f)
  end

  content = files.map { |f| File.read(f) }.join
  Digest::MD5.hexdigest(content << digest_component).to_s
end

#excluded_files(template) ⇒ Object



17
18
19
20
21
# File 'lib/commands/exercise/render_methods.rb', line 17

def excluded_files(template)
  all_files_templates = files(templates_directory(template))
  rendered_files = all_files_templates.collect { |t| filename(t) }.find_all { |f| File.exist?(f) }
  all_files_templates.reject { |file| file == template }.concat(rendered_files)
end

#paths(*paths) ⇒ Object



23
24
25
# File 'lib/commands/exercise/render_methods.rb', line 23

def paths(*paths)
  paths.find_all { |excluded_file| File.exist?(excluded_file) }.collect { |path| full_path(path) }
end