Class: INatGet::App::Task
- Inherits:
-
Object
- Object
- INatGet::App::Task
- Includes:
- Data::DSL
- Defined in:
- lib/inat-get/app/core/task.rb
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
-
#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, #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.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/inat-get/app/core/task.rb', line 26 def initialize path, config, **opts @config = config @path = path @name = File.basename path, '.*' @opts = opts @console = opts[:console] @api = opts[:api] inner_code = File.read @path outer_code = "define_singleton_method :execute do\n" + "#{ inner_code }\n" + "end\n" instance_eval outer_code end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
40 41 42 |
# File 'lib/inat-get/app/core/task.rb', line 40 def db @db end |
#name ⇒ Object
Returns the value of attribute name.
19 20 21 |
# File 'lib/inat-get/app/core/task.rb', line 19 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/inat-get/app/core/task.rb', line 17 def path @path end |
Instance Method Details
#logger ⇒ Object (private)
83 84 85 |
# File 'lib/inat-get/app/core/task.rb', line 83 def logger @logger ||= INatGet::App::ConsoleLogger::new @console, progname: self.name end |
#prepare ⇒ Object
42 43 44 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 78 79 |
# File 'lib/inat-get/app/core/task.rb', line 42 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("common.log", level: :info) require_relative '../../data/models/observation' require_relative '../../data/managers/places' require_relative '../../data/managers/projects' require_relative '../../data/managers/users' require_relative '../../data/managers/taxa' require_relative '../../data/managers/observations' require_relative '../../data/managers/identifications' # # ... etc end |