Class: INat::App::Task::Context

Inherits:
Object
  • Object
show all
Includes:
INat, INat::App, DSL, Report, Report::DSL, Report::Table::DSL
Defined in:
lib/inat/app/task/context.rb

Constant Summary

Constants included from Report::DSL

Report::DSL::LAST_STYLE, Report::DSL::SUMMARY_STYLE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Report::Table::DSL

#table, table

Methods included from Report::DSL

#class_title, #history_table, history_table, #rating_table, rating_table, #species_table, species_table, summary_table, #summary_table

Methods included from DSL

#select, select

Methods included from Logger::DSL

#debug, debug, echo, #echo, error, #error, #info, info, log, #log, #warning, warning

Constructor Details

#initialize(task, name, path) ⇒ Context

Returns a new instance of Context.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/inat/app/task/context.rb', line 31

def initialize task, name, path
  @task = task
  @name = name
  @done = false
  source_code = File.readlines(path).map { |line| "    #{line}" }.join('')
  full_code = "define_singleton_method :execute do\n" +
              "  begin\n" +
              "    #{source_code}\n" +
              "    Status::status nil, 'DONE'\n" +
              "  rescue Exception => e\n" +
              "    error \"\#{e.inspect}\"\n" +
              "    error \"\#{e.backtrace.join(\"\\n\\t\")}\"\n" +
              "    Status::status nil, 'ERROR : ' + e.inspect\n" +
              "  rescue\n" +
              "    error 'Unknown error!'\n" +
              "    Status::status nil, 'ERROR'\n" +
              "  end\n" +
              "  @done = true\n" +
              "end"
  self.instance_eval full_code
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/inat/app/task/context.rb', line 17

def name
  @name
end

Instance Method Details

#configObject



19
20
21
# File 'lib/inat/app/task/context.rb', line 19

def config
  @task.config
end

#done?Boolean

Returns:



27
28
29
# File 'lib/inat/app/task/context.rb', line 27

def done?
  @done
end

#loggerObject



23
24
25
# File 'lib/inat/app/task/context.rb', line 23

def logger
  @task.logger
end