Class: Polytrix::Implementor

Inherits:
ManifestSection show all
Includes:
Executor, Logging, Util::FileSystem
Defined in:
lib/polytrix/implementor.rb

Defined Under Namespace

Classes: GitOptions

Instance Attribute Summary

Attributes included from Executor

#env, #executor

Instance Method Summary collapse

Methods included from Executor

#execute

Methods included from Util::FileSystem

#find_file, #relativize

Methods included from Util::String

included

Methods included from Util::String::ClassMethods

#ansi2html, #escape_html, #highlight, #slugify

Constructor Details

#initialize(data) ⇒ Implementor

Returns a new instance of Implementor.



32
33
34
35
# File 'lib/polytrix/implementor.rb', line 32

def initialize(data)
  data[:basedir] = File.absolute_path(data[:basedir])
  super
end

Instance Method Details

#bootstrapObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/polytrix/implementor.rb', line 58

def bootstrap
  # Logging.mdc['implementor'] = name
  banner "Bootstrapping #{name}"
  fail "Implementor #{name} has not been cloned" unless cloned?

  execute('./scripts/bootstrap', cwd: basedir, prefix: name)
rescue ExecutionError => e
  if e.cause.is_a? Errno::ENOENT
    logger.warn "Skipping bootstrapping for #{name}, no script/bootstrap exists"
  else
    raise e
  end
end

#build_challenge(challenge_data) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/polytrix/implementor.rb', line 72

def build_challenge(challenge_data)
  challenge_data[:basedir] ||= basedir
  challenge_data[:implementor] ||= self
  challenge_data[:suite] ||= ''
  begin
    challenge_data[:source_file] ||= find_file basedir, challenge_data[:name]
    challenge_data[:source_file] = relativize(challenge_data[:source_file], challenge_data[:basedir])
  rescue Errno::ENOENT
    challenge_data[:source_file] = nil
  end
  Challenge.new challenge_data
end

#cloneObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/polytrix/implementor.rb', line 41

def clone
  # Logging.mdc['implementor'] = name
  if git.nil? || git.repo.nil?
    logger.info 'Skipping clone because there are no git options'
    return
  end
  branch = git.branch ||= 'master'
  target_dir = git.to ||= basedir
  if File.exist? target_dir
    logger.info "Skipping clone because #{target_dir} already exists"
  else
    clone_cmd = "git clone #{git.repo} -b #{branch} #{target_dir}"
    logger.info "Cloning: #{clone_cmd}"
    execute clone_cmd
  end
end

#cloned?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/polytrix/implementor.rb', line 85

def cloned?
  File.directory? basedir
end

#loggerObject



37
38
39
# File 'lib/polytrix/implementor.rb', line 37

def logger
  @logger ||= Polytrix::Logger.new_logger(self)
end