Class: Mumukit::Templates::FileHook

Inherits:
Hook
  • Object
show all
Includes:
WithTempfile
Defined in:
lib/mumukit/templates/file_hook.rb

Direct Known Subclasses

MultiFileHook, TryHook

Instance Attribute Summary collapse

Attributes inherited from Hook

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithTempfile

#create_tempfile, #mask_tempfile_references, #tempfile_extension, #with_tempfile, #write_tempdir!, #write_tempfile!

Methods inherited from Hook

#env, #initialize, #logger, #method_missing, #should_forward_to_config?, stateful_through, #t

Methods included from WithContentType

#content_type

Constructor Details

This class inherits a constructor from Mumukit::Hook

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mumukit::Hook

Instance Attribute Details

#requestObject

Returns the value of attribute request.



5
6
7
# File 'lib/mumukit/templates/file_hook.rb', line 5

def request
  @request
end

Class Method Details

.isolated(value = true) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/mumukit/templates/file_hook.rb', line 59

def self.isolated(value=true)
  if value
    include Mumukit::Templates::WithIsolatedEnvironment
  else
    include Mumukit::Templates::WithEmbeddedEnvironment
  end
end

.line_number_offset(offset, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/mumukit/templates/file_hook.rb', line 36

def self.line_number_offset(offset, options={})
  include Mumukit::Templates::WithLineNumberOffset

  define_method(:line_number_offset) do
    extra_offset = options[:include_extra] && request.extra ? request.extra.lines.length : 0
    offset + extra_offset
  end
end

.mashup(*args, &map_block) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/mumukit/templates/file_hook.rb', line 67

def self.mashup(*args, &map_block)
  include Mumukit::Templates::WithMashupFileContent
  define_method(:map_mashup_fields, &map_block) if block_given?

  args = args.present? ? args : [:extra, :content, :test]

  if args
    define_method(:mashup_fields) { args }
  end
end

.metatested(value = true) ⇒ Object



45
46
47
48
49
50
# File 'lib/mumukit/templates/file_hook.rb', line 45

def self.metatested(value=true)
  if value
    include Mumukit::Templates::WithMetatest
    include Mumukit::Templates::WithMetatestResults
  end
end

.structured(value = true, separator: nil) ⇒ Object



52
53
54
55
56
57
# File 'lib/mumukit/templates/file_hook.rb', line 52

def self.structured(value=true, separator: nil)
  if value
    @separator = separator
    include Mumukit::Templates::WithStructuredResults
  end
end

.with_error_patternsObject



78
79
80
# File 'lib/mumukit/templates/file_hook.rb', line 78

def self.with_error_patterns
  include Mumukit::Templates::WithErrorPatterns
end

Instance Method Details

#cleanup_raw_result(result) ⇒ Object



19
20
21
# File 'lib/mumukit/templates/file_hook.rb', line 19

def cleanup_raw_result(result)
  mask_tempfile_references(result.force_encoding('UTF-8'), masked_tempfile_path)
end

#compile(request) ⇒ Object



7
8
9
10
# File 'lib/mumukit/templates/file_hook.rb', line 7

def compile(request)
  self.request = request
  write_tempfile! compile_file_content(request)
end

#masked_tempfile_pathObject



32
33
34
# File 'lib/mumukit/templates/file_hook.rb', line 32

def masked_tempfile_path
  @masked_tempfile_path ||= "#{t 'mumukit.masked_tempfile_basename'}#{tempfile_extension}"
end

#post_process_file(file, result, status) ⇒ Object



23
24
25
# File 'lib/mumukit/templates/file_hook.rb', line 23

def post_process_file(file, result, status)
  [result, status]
end

#run!(file) ⇒ Object



12
13
14
15
16
17
# File 'lib/mumukit/templates/file_hook.rb', line 12

def run!(file)
  result, status = run_file!(file)
  post_process_file(file, cleanup_raw_result(result), status)
ensure
  file.unlink
end