Class: Contest::Driver::DriverBase

Inherits:
DriverEvent show all
Defined in:
lib/contest/driver/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DriverEvent

#off, #on, #trigger

Constructor Details

#initialize(new_args = []) ⇒ DriverBase

Returns a new instance of DriverBase.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/contest/driver/base.rb', line 22

def initialize(new_args = [])
  @args = new_args.clone
  # submit options
  @options ||= {}
  # site config
  @config ||= {}
  @config["file"] ||= {}
  @config["submit_rules"] ||= {}
  # call DriverEvent#initialize
  super()
  initialize_ext
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



20
21
22
# File 'lib/contest/driver/base.rb', line 20

def args
  @args
end

#configObject

Returns the value of attribute config.



18
19
20
# File 'lib/contest/driver/base.rb', line 18

def config
  @config
end

#optionsObject

Returns the value of attribute options.



19
20
21
# File 'lib/contest/driver/base.rb', line 19

def options
  @options
end

Instance Method Details

#define_options(&block) ⇒ Object



72
73
74
75
# File 'lib/contest/driver/base.rb', line 72

def define_options &block
  @blocks ||= []
  @blocks.push(block)
end

#get_commit_message(status) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/contest/driver/base.rb', line 112

def get_commit_message status
  if @options[:message].nil?
    message = @config["submit_rules"]["message"] || DEFAULT_COMMIT_MESSAGE
    message = message.gsub '${site}', get_site_name
    message = message.gsub '${problem-id}', get_problem_id(options)
    message = message.gsub '${status}', status
    message = "\n#{get_commit_message_ext}" unless get_commit_message_ext.nil?
  else
    message = @options[:message]
  end
  message
end

#get_commit_message_extObject



108
109
110
# File 'lib/contest/driver/base.rb', line 108

def get_commit_message_ext
  nil
end

#get_descObject



68
69
70
# File 'lib/contest/driver/base.rb', line 68

def get_desc
  ''
end

#get_optsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/contest/driver/base.rb', line 77

def get_opts
  get_opts_ext()
  define_options do
    opt(
      :source,
      "Specify submitted code (Ex: main.cpp)",
      :type => :string,
      :required => false,
    )
    opt(
      :language,
      "Specify programming language (Ex: C++, Java or etc...)",
      :type => :string,
      :required => false,
    )
    opt(
      :message,
      "Set git-commit message",
      :type => :string,
      :required => false,
    )
  end
  Trollop::options args, @blocks do |blocks|
    version "git-contest driver"
    # set driver options
    blocks.each do |b|
      instance_eval &b
    end
  end
end

#get_opts_extObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/contest/driver/base.rb', line 39

def get_opts_ext
  # Example:
  # define_options do
  #   opt(
  #     :problem_id,
  #     "Problem ID (Ex: 1000, 123, 0123, etc...)",
  #     :type => :string,
  #     :required => true,
  #   )
  # end
  raise 'TODO: Implement'
end

#get_problem_id(options) ⇒ Object



56
57
58
# File 'lib/contest/driver/base.rb', line 56

def get_problem_id(options)
  raise 'TODO: Implement'
end

#get_site_nameObject



52
53
54
# File 'lib/contest/driver/base.rb', line 52

def get_site_name
  raise 'TODO: Implement'
end

#initialize_extObject



35
36
37
# File 'lib/contest/driver/base.rb', line 35

def initialize_ext
  nil
end

#resolve_language(label) ⇒ Object



60
61
62
# File 'lib/contest/driver/base.rb', line 60

def resolve_language(label)
  raise 'TODO: Implement'
end

#submitObject

submit a solution



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/contest/driver/base.rb', line 126

def submit
  @options[:source] = Utils.resolve_path(
    @options[:source] || @config["submit_rules"]["source"] || DEFAULT_SOURCE_PATH
  )
  if Utils.check_file_map(@options[:source], @config["file"]["ext"])
    @options[:language] ||= Utils.resolve_file_map(@options[:source], @config["file"]["ext"])
  else
    @options[:language] ||= Utils.resolve_language(@options[:source])
  end
  @options[:language] = resolve_language Utils.normalize_language(@options[:language])

  submit_ext()
end

#submit_ext(config, source_path, options) ⇒ Object



64
65
66
# File 'lib/contest/driver/base.rb', line 64

def submit_ext(config, source_path, options)
  raise 'TODO: Implement'
end