Commit 164d7f0e by Đường Sỹ Hoàng

Config setting

parent e1e676c8
......@@ -34,3 +34,7 @@
/yarn-error.log
yarn-debug.log*
.yarn-integrity
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
......@@ -33,6 +33,7 @@ gem "mechanize"
gem "rubysl-open-uri"
gem "whenever", require: false
gem "activerecord-import"
gem "config"
group :development, :test do
# Call "byebug" anywhere in the code to stop execution and get a debugger console
......
......@@ -78,8 +78,13 @@ GEM
chronic (0.10.2)
coderay (1.1.2)
concurrent-ruby (1.1.5)
config (2.0.0)
activesupport (>= 4.2)
deep_merge (~> 1.2, >= 1.2.1)
dry-schema (~> 1.0)
connection_pool (2.2.2)
crass (1.0.5)
deep_merge (1.2.1)
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
......@@ -88,6 +93,36 @@ GEM
warden (~> 1.2.3)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dry-configurable (0.9.0)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4, >= 0.4.7)
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.9)
concurrent-ruby (~> 1.0)
dry-equalizer (0.3.0)
dry-inflector (0.2.0)
dry-initializer (3.0.2)
dry-logic (1.0.5)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-schema (1.4.1)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.8, >= 0.8.3)
dry-core (~> 0.4)
dry-equalizer (~> 0.2)
dry-initializer (~> 3.0)
dry-logic (~> 1.0)
dry-types (~> 1.2)
dry-types (1.2.1)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
dry-equalizer (~> 0.2, >= 0.2.2)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
erubi (1.9.0)
ffi (1.11.3)
globalid (0.4.2)
......@@ -252,6 +287,7 @@ DEPENDENCIES
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
config
devise
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
......
......@@ -3,3 +3,8 @@ require_relative "application"
# Initialize the Rails application.
Rails.application.initialize!
# # Rails.logger = Logger.new(STDOUT)
# # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
# Rails.logger = Logger.new(STDOUT)
# Rails.logger.level = Logger::DEBUG
# Rails.logger.datetime_format = "%Y-%m-%d %H:%M:%S"
Config.setup do |config|
# Name of the constant exposing loaded settings
config.const_name = 'Settings'
# Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
#
# config.knockout_prefix = nil
# Overwrite an existing value when merging a `nil` value.
# When set to `false`, the existing value is retained after merge.
#
# config.merge_nil_values = true
# Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
#
# config.overwrite_arrays = true
# Load environment variables from the `ENV` object and override any settings defined in files.
#
# config.use_env = false
# Define ENV variable prefix deciding which variables to load into config.
#
# config.env_prefix = 'Settings'
# What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
# with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
# using dots in variable names might not be allowed (eg. Bash).
#
# config.env_separator = '.'
# Ability to process variables names:
# * nil - no change
# * :downcase - convert to lower case
#
# config.env_converter = :downcase
# Parse numeric values as integers instead of strings.
#
# config.env_parse_values = true
# Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
#
# config.schema do
# required(:name).filled
# required(:age).maybe(:int?)
# required(:email).filled(format?: EMAIL_REGEX)
# end
end
import_job:
csv_file: db/Venjob.csv
......@@ -3,28 +3,31 @@ require "csv"
namespace :job do
desc "Import CSV file into database"
task import_csv: :environment do
CSV.foreach("db/Venjob.csv", headers: true) do |row|
csv_file = Settings.import_job.csv_file
CSV.foreach(csv_file, headers: true) do |row|
company_params = {
email: row["contact email"],
name: row["company name"],
address: row["company address"],
code: row["company id"]
}
Company.create!(company_params)
company = Company.find_or_initialize_by(code: row["company id"])
company.update(company_params)
job_params = {
company_id: Company.find_by(code: row["company id"]).id,
company_id: company.id,
title: row["name"],
description: row["description"],
position: row["level"],
salary: row["salary"],
requirement: row["requirement"]
}
Job.create!(job_params)
end
rescue
import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.info "Skip #{row}"
next
job = Job.find_or_initialize_by(title: row["name"])
job.update(job_params)
rescue
import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.error "Skip #{row}"
next
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment