module Exercise::Helpers
Public Instance Methods
all_files_in(name)
click to toggle source
# File lib/commands/exercise/command.rb, line 77 def all_files_in(name) Dir.glob("#{name}/**/*", File::FNM_DOTMATCH).find_all { |file| !%w[. ..].include?(File.basename(file)) } end
all_updated(paths, project_root_dir)
click to toggle source
# File lib/commands/exercise/command.rb, line 81 def all_updated(paths, project_root_dir) paths.find_all { |path| template_updated?(path, project_root_dir) }.collect do |template| Template.new(template, project_root_dir) end end
exercise_directories(path)
click to toggle source
# File lib/commands/exercise/command.rb, line 91 def exercise_directories(path) Dir["#{path}/**/.templates"] end
exercise_structure()
click to toggle source
# File lib/commands/exercise/command.rb, line 87 def exercise_structure @exercise_structure ||= YAML.safe_load(File.read(ENV['SCAFFOLD_STRUCTURE'])) end
process_template(original_dir, template)
click to toggle source
# File lib/commands/exercise/command.rb, line 101 def process_template(original_dir, template) template_dir = template.dir Dir.chdir template_dir ENV['exercise_path'] = template_dir.gsub(original_dir, '') ENV['CIC_PWD'] = "#{ENV['CIC_PWD']}/#{template.relative_path(template_dir, original_dir)}" print_rendering_banner(template.path) !render_exercise(template.path, digest_component: options[:digest_component]) ensure ENV['CIC_PWD'] = original_dir Dir.chdir original_dir end
quiet?()
click to toggle source
# File lib/commands/exercise/command.rb, line 113 def quiet? options[:verbose] == false end
register_environment(environment_variables_string)
click to toggle source
# File lib/commands/exercise/command.rb, line 121 def register_environment(environment_variables_string) environment_variables = environment_variables_string.to_s.scan(%r{([\w+.]+)\s*=\s*([\w+./-]+)?}).to_h environment_variables.each { |key, value| ENV[key] = value } end
scaffold_path()
click to toggle source
# File lib/commands/exercise/command.rb, line 117 def scaffold_path @scaffold_path ||= ENV['SCAFFOLD_PATH'] end
template_updated?(template, project_root_dir)
click to toggle source
# File lib/commands/exercise/command.rb, line 132 def template_updated?(template, project_root_dir) template = template.is_a?(String) ? Template.new(template, project_root_dir) : template return true unless File.exist?(template.rendered_file_path) digest = digest(path: template.dir, digest_component: options[:digest_component], excludes: excluded_files(template.full_path)) !File.read(template.rendered_file_path).include?(digest) end
templates(path)
click to toggle source
# File lib/commands/exercise/command.rb, line 126 def templates(path) exercise_directories(path).collect do |templates_dir| Dir["#{File.expand_path(templates_dir)}/*.md.erb"] end.flatten end