Class: Mumukit::Templates::FileHook

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

Direct Known Subclasses

MulangExpectationsHook

Instance Attribute Summary

Attributes inherited from Hook

#config

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithTempfile

#create_tempfile, #tempfile_extension, #with_tempfile, #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

Class Method Details

.isolated(value = true) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/mumukit/templates/file_hook.rb', line 31

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

.mashup(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/mumukit/templates/file_hook.rb', line 39

def self.mashup(*args)
  include Mumukit::Templates::WithMashupFileContent

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

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

.structured(value = true) ⇒ Object



25
26
27
28
29
# File 'lib/mumukit/templates/file_hook.rb', line 25

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

Instance Method Details

#compile(request) ⇒ Object



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

def compile(request)
  write_tempfile! compile_file_content(request)
end

#post_process_file(file, result, status) ⇒ Object



16
17
18
# File 'lib/mumukit/templates/file_hook.rb', line 16

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

#run!(file) ⇒ Object



9
10
11
12
13
14
# File 'lib/mumukit/templates/file_hook.rb', line 9

def run!(file)
  result, status = run_file!(file)
  post_process_file(file, result.force_encoding('UTF-8'), status)
ensure
  file.unlink
end