Class: INatGet::App::Task
- Inherits:
-
Object
- Object
- INatGet::App::Task
- Includes:
- Data::DSL
- Defined in:
- lib/inat-get/app/core/task.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ERB
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(path, config, **opts) ⇒ Task
constructor
A new instance of Task.
- #logger ⇒ Object private
- #prepare ⇒ Object
Methods included from Data::DSL
#AND, #ANYTHING, #NOT, #NOTHING, #OR, #Q, #console, #erb_report, #finish_time, #get_identification, #get_observation, #get_place, #get_project, #get_taxon, #get_user, #now, #select_identifications, #select_observations, #select_places, #select_projects, #select_taxa, #select_users, #start_time, #time_range, #today, #version, #version!, #version?, #version_alias
Constructor Details
#initialize(path, config, **opts) ⇒ Task
Returns a new instance of Task.
29 30 31 32 33 34 35 36 37 |
# File 'lib/inat-get/app/core/task.rb', line 29 def initialize path, config, **opts @config = config @path = path @name = File.basename path, '.*' @opts = opts @console = opts[:console] @api = opts[:api] @code = File.read @path end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
43 44 45 |
# File 'lib/inat-get/app/core/task.rb', line 43 def db @db end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/inat-get/app/core/task.rb', line 22 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/inat-get/app/core/task.rb', line 20 def path @path end |
Instance Method Details
#execute ⇒ Object
39 40 41 |
# File 'lib/inat-get/app/core/task.rb', line 39 def execute instance_eval @code, @path end |
#logger ⇒ Object (private)
81 82 83 |
# File 'lib/inat-get/app/core/task.rb', line 81 def logger @logger ||= INatGet::App::ConsoleLogger::new @console, progname: self.name end |
#prepare ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/inat-get/app/core/task.rb', line 45 def prepare Thread::current[:api] = @api Thread::current[:console] = @console Thread::current[:logger] = logger db_connect = @config.dig(:database, :connect) = { user: @config.dig(:database, :user), password: @config.dig(:database, :password) }.compact @db = Sequel::connect(db_connect, **) if @db.database_type == :sqlite @db.extend_datasets do def literal_datetime(value) "'#{value.xmlschema}'" end def literal_time(value) if value.instance_of?(::Time) "'#{value.xmlschema}'" else super(value) end end end @db.execute 'PRAGMA journal_mode=WAL' @db.execute 'PRAGMA synchronous=NORMAL' @db.execute 'PRAGMA busy_timeout=5000000' end Sequel::Model.require_valid_table = false Sequel::Model.strict_param_setting = false Sequel::Model.raise_on_save_failure = true Sequel::Model.db = @db Sequel::Model.db.loggers << ::Logger::new("sequel.log", level: :info) require_relative '../../data/models' require_relative '../../data/managers' # # ... etc end |