From 7d253b3ec0162b655bea2c98f1a36da7105c250e Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 09:37:11 -0600 Subject: [PATCH 1/4] format --- app/controllers/translates_controller.rb | 65 +++++++++++-------- config/environments/production.rb | 8 +-- config/puma.rb | 10 +-- db/schema.rb | 2 - .../controllers/translates_controller_test.rb | 32 +++++++-- 5 files changed, 72 insertions(+), 45 deletions(-) diff --git a/app/controllers/translates_controller.rb b/app/controllers/translates_controller.rb index c42704a..41adcc5 100644 --- a/app/controllers/translates_controller.rb +++ b/app/controllers/translates_controller.rb @@ -7,22 +7,33 @@ def create reader_name = params[:reader] writer_name = params[:writer] - @md_return = ADIWG::Mdtranslator.translate( - file: file_obj, reader: reader_name, writer: writer_name - ) + @md_return = + ADIWG::Mdtranslator.translate( + file: file_obj, + reader: reader_name, + writer: writer_name + ) @response_info = {} @response_info[:success] = true - @response_info[:readerStructureStatus] = 'OK' - @response_info[:readerStructureMessages] = @md_return[:readerStructureMessages] - @response_info[:readerValidationStatus] = 'OK' - @response_info[:readerValidationMessages] = @md_return[:readerValidationMessages] - @response_info[:readerExecutionStatus] = 'OK' - @response_info[:readerExecutionMessages] = @md_return[:readerExecutionMessages] - @response_info[:writerStatus] = 'OK' + @response_info[:readerStructureStatus] = "OK" + @response_info[:readerStructureMessages] = @md_return[ + :readerStructureMessages + ] + @response_info[:readerValidationStatus] = "OK" + @response_info[:readerValidationMessages] = @md_return[ + :readerValidationMessages + ] + @response_info[:readerExecutionStatus] = "OK" + @response_info[:readerExecutionMessages] = @md_return[ + :readerExecutionMessages + ] + @response_info[:writerStatus] = "OK" @response_info[:writerMessages] = @md_return[:writerMessages] @response_info[:readerRequested] = @md_return[:readerRequested] - @response_info[:readerVersionRequested] = @md_return[:readerVersionRequested] + @response_info[:readerVersionRequested] = @md_return[ + :readerVersionRequested + ] @response_info[:readerVersionUsed] = @md_return[:readerVersionUsed] @response_info[:writerRequested] = @md_return[:writerRequested] @response_info[:writerVersion] = @md_return[:writerVersion] @@ -40,28 +51,28 @@ def create a_e_mess = @response_info[:readerExecutionMessages] a_w_mess = @response_info[:writerMessages] - status = 'OK' - status = 'NOTICE' if a_s_mess.any? { |s| s.include?('NOTICE') } - status = 'WARNING' if a_s_mess.any? { |s| s.include?('WARNING') } - status = 'ERROR' if a_s_mess.any? { |s| s.include?('ERROR') } + status = "OK" + status = "NOTICE" if a_s_mess.any? { |s| s.include?("NOTICE") } + status = "WARNING" if a_s_mess.any? { |s| s.include?("WARNING") } + status = "ERROR" if a_s_mess.any? { |s| s.include?("ERROR") } @response_info[:readerStructureStatus] = status - status = 'OK' - status = 'NOTICE' if a_v_mess.any? { |s| s.include?('NOTICE') } - status = 'WARNING' if a_v_mess.any? { |s| s.include?('WARNING') } - status = 'ERROR' if a_v_mess.any? { |s| s.include?('ERROR') } + status = "OK" + status = "NOTICE" if a_v_mess.any? { |s| s.include?("NOTICE") } + status = "WARNING" if a_v_mess.any? { |s| s.include?("WARNING") } + status = "ERROR" if a_v_mess.any? { |s| s.include?("ERROR") } @response_info[:readerValidationStatus] = status - status = 'OK' - status = 'NOTICE' if a_e_mess.any? { |s| s.include?('NOTICE') } - status = 'WARNING' if a_e_mess.any? { |s| s.include?('WARNING') } - status = 'ERROR' if a_e_mess.any? { |s| s.include?('ERROR') } + status = "OK" + status = "NOTICE" if a_e_mess.any? { |s| s.include?("NOTICE") } + status = "WARNING" if a_e_mess.any? { |s| s.include?("WARNING") } + status = "ERROR" if a_e_mess.any? { |s| s.include?("ERROR") } @response_info[:readerExecutionStatus] = status - status = 'OK' - status = 'NOTICE' if a_w_mess.any? { |s| s.include?('NOTICE') } - status = 'WARNING' if a_w_mess.any? { |s| s.include?('WARNING') } - status = 'ERROR' if a_w_mess.any? { |s| s.include?('ERROR') } + status = "OK" + status = "NOTICE" if a_w_mess.any? { |s| s.include?("NOTICE") } + status = "WARNING" if a_w_mess.any? { |s| s.include?("WARNING") } + status = "ERROR" if a_w_mess.any? { |s| s.include?("ERROR") } @response_info[:writerStatus] = status # check for errors returned by parser, validator, reader, and writer diff --git a/config/environments/production.rb b/config/environments/production.rb index 4a7cefd..bb5dbfa 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -21,7 +21,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -75,10 +75,10 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new($stdout) + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/config/puma.rb b/config/puma.rb index 69e2645..fef891b 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,20 +6,20 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) -min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT', 3000) +port ENV.fetch("PORT", 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch('RAILS_ENV', 'development') +environment ENV.fetch("RAILS_ENV", "development") # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') +pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/db/schema.rb b/db/schema.rb index 3dbcc5d..baa6d51 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2023_12_26_174535) do - create_table "translates", force: :cascade do |t| t.binary "file" t.string "reader" @@ -19,5 +18,4 @@ t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false end - end diff --git a/test/controllers/translates_controller_test.rb b/test/controllers/translates_controller_test.rb index ef51565..f91382b 100644 --- a/test/controllers/translates_controller_test.rb +++ b/test/controllers/translates_controller_test.rb @@ -1,19 +1,37 @@ # frozen_string_literal: true -require 'test_helper' +require "test_helper" class TranslatesControllerTest < ActionDispatch::IntegrationTest - test 'post valid transformation of sbJson to mdJson' do + test "post valid transformation of sbJson to mdJson" do @translate = translates(:sbjson_to_mdjson) - @file = File.read(File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}")) - post '/translates', params: { file: @file, reader: @translate.reader, writer: @translate.writer }, as: :json + @file = + File.read( + File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}") + ) + post "/translates", + params: { + file: @file, + reader: @translate.reader, + writer: @translate.writer + }, + as: :json assert_response 200 end - test 'post invalid transformation of fgdc to iso19115_3' do + test "post invalid transformation of fgdc to iso19115_3" do @translate = translates(:fgdc_to_iso) - @file = File.read(File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}")) - post '/translates', params: { file: @file, reader: @translate.reader, writer: @translate.writer }, as: :json + @file = + File.read( + File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}") + ) + post "/translates", + params: { + file: @file, + reader: @translate.reader, + writer: @translate.writer + }, + as: :json assert_response 422 end end From 9a83a87faa1e7e019ecefcd3eb822bbb4632203e Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 09:37:29 -0600 Subject: [PATCH 2/4] add syntax_tree lib --- Gemfile | 1 + Gemfile.lock | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Gemfile b/Gemfile index a8deea1..98c45ee 100644 --- a/Gemfile +++ b/Gemfile @@ -43,6 +43,7 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' + gem 'syntax_tree', '~>6.2.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index 6c0bc5b..cd7b9d1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,6 +131,7 @@ GEM parser (3.2.2.4) ast (~> 2.4.1) racc + prettier_print (1.2.1) psych (3.3.4) public_suffix (5.0.4) puma (4.3.12) @@ -206,6 +207,8 @@ GEM sprockets (>= 3.0.0) sqlite3 (1.6.9-arm64-darwin) sqlite3 (1.6.9-x86_64-linux) + syntax_tree (6.2.0) + prettier_print (>= 1.2.0) thor (0.20.3) thread_safe (0.3.6) timeout (0.4.1) @@ -234,6 +237,7 @@ DEPENDENCIES spring spring-watcher-listen (~> 2.0.0) sqlite3 (~> 1.4) + syntax_tree (~> 6.2.0) tzinfo-data RUBY VERSION From 3828eed8321732a1c045d412a704299d5cae28f5 Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 09:37:42 -0600 Subject: [PATCH 3/4] add format command --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9a97b1e..a6d5f22 100644 --- a/Makefile +++ b/Makefile @@ -9,4 +9,8 @@ lint: .PHONY: test test: - rails test \ No newline at end of file + rails test + +# recursively finds all .rb files in the current dir and formats them using stree +format: + find . -type f -name "*.rb" | xargs -L1 bundle exec stree write --plugins=plugin/single_quotes \ No newline at end of file From 375dc1a7a9c8667c9a09fd31a2c3bf5fee166cbd Mon Sep 17 00:00:00 2001 From: Reid Hewitt Date: Thu, 25 Apr 2024 09:38:39 -0600 Subject: [PATCH 4/4] format --- app/controllers/translates_controller.rb | 40 +++++++++---------- config/environments/production.rb | 4 +- config/environments/test.rb | 2 +- config/initializers/wrap_parameters.rb | 4 +- config/puma.rb | 10 ++--- db/schema.rb | 12 +++--- .../controllers/translates_controller_test.rb | 10 ++--- test/models/translate_test.rb | 12 ++++-- 8 files changed, 48 insertions(+), 46 deletions(-) diff --git a/app/controllers/translates_controller.rb b/app/controllers/translates_controller.rb index 41adcc5..517103a 100644 --- a/app/controllers/translates_controller.rb +++ b/app/controllers/translates_controller.rb @@ -16,19 +16,19 @@ def create @response_info = {} @response_info[:success] = true - @response_info[:readerStructureStatus] = "OK" + @response_info[:readerStructureStatus] = 'OK' @response_info[:readerStructureMessages] = @md_return[ :readerStructureMessages ] - @response_info[:readerValidationStatus] = "OK" + @response_info[:readerValidationStatus] = 'OK' @response_info[:readerValidationMessages] = @md_return[ :readerValidationMessages ] - @response_info[:readerExecutionStatus] = "OK" + @response_info[:readerExecutionStatus] = 'OK' @response_info[:readerExecutionMessages] = @md_return[ :readerExecutionMessages ] - @response_info[:writerStatus] = "OK" + @response_info[:writerStatus] = 'OK' @response_info[:writerMessages] = @md_return[:writerMessages] @response_info[:readerRequested] = @md_return[:readerRequested] @response_info[:readerVersionRequested] = @md_return[ @@ -51,28 +51,28 @@ def create a_e_mess = @response_info[:readerExecutionMessages] a_w_mess = @response_info[:writerMessages] - status = "OK" - status = "NOTICE" if a_s_mess.any? { |s| s.include?("NOTICE") } - status = "WARNING" if a_s_mess.any? { |s| s.include?("WARNING") } - status = "ERROR" if a_s_mess.any? { |s| s.include?("ERROR") } + status = 'OK' + status = 'NOTICE' if a_s_mess.any? { |s| s.include?('NOTICE') } + status = 'WARNING' if a_s_mess.any? { |s| s.include?('WARNING') } + status = 'ERROR' if a_s_mess.any? { |s| s.include?('ERROR') } @response_info[:readerStructureStatus] = status - status = "OK" - status = "NOTICE" if a_v_mess.any? { |s| s.include?("NOTICE") } - status = "WARNING" if a_v_mess.any? { |s| s.include?("WARNING") } - status = "ERROR" if a_v_mess.any? { |s| s.include?("ERROR") } + status = 'OK' + status = 'NOTICE' if a_v_mess.any? { |s| s.include?('NOTICE') } + status = 'WARNING' if a_v_mess.any? { |s| s.include?('WARNING') } + status = 'ERROR' if a_v_mess.any? { |s| s.include?('ERROR') } @response_info[:readerValidationStatus] = status - status = "OK" - status = "NOTICE" if a_e_mess.any? { |s| s.include?("NOTICE") } - status = "WARNING" if a_e_mess.any? { |s| s.include?("WARNING") } - status = "ERROR" if a_e_mess.any? { |s| s.include?("ERROR") } + status = 'OK' + status = 'NOTICE' if a_e_mess.any? { |s| s.include?('NOTICE') } + status = 'WARNING' if a_e_mess.any? { |s| s.include?('WARNING') } + status = 'ERROR' if a_e_mess.any? { |s| s.include?('ERROR') } @response_info[:readerExecutionStatus] = status - status = "OK" - status = "NOTICE" if a_w_mess.any? { |s| s.include?("NOTICE") } - status = "WARNING" if a_w_mess.any? { |s| s.include?("WARNING") } - status = "ERROR" if a_w_mess.any? { |s| s.include?("ERROR") } + status = 'OK' + status = 'NOTICE' if a_w_mess.any? { |s| s.include?('NOTICE') } + status = 'WARNING' if a_w_mess.any? { |s| s.include?('WARNING') } + status = 'ERROR' if a_w_mess.any? { |s| s.include?('ERROR') } @response_info[:writerStatus] = status # check for errors returned by parser, validator, reader, and writer diff --git a/config/environments/production.rb b/config/environments/production.rb index bb5dbfa..a88c131 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -21,7 +21,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -75,7 +75,7 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/config/environments/test.rb b/config/environments/test.rb index 8f2c428..c34d0be 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -23,7 +23,7 @@ } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 2f3c0db..a02673e 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -6,9 +6,7 @@ # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] -end +ActiveSupport.on_load(:action_controller) { wrap_parameters format: [:json] } # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do diff --git a/config/puma.rb b/config/puma.rb index fef891b..23b78f4 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,20 +6,20 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) +min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT", 3000) +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV", "development") +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/db/schema.rb b/db/schema.rb index baa6d51..4d74375 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,11 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2023_12_26_174535) do - create_table "translates", force: :cascade do |t| - t.binary "file" - t.string "reader" - t.string "writer" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + create_table 'translates', force: :cascade do |t| + t.binary 'file' + t.string 'reader' + t.string 'writer' + t.datetime 'created_at', precision: 6, null: false + t.datetime 'updated_at', precision: 6, null: false end end diff --git a/test/controllers/translates_controller_test.rb b/test/controllers/translates_controller_test.rb index f91382b..24ea1c7 100644 --- a/test/controllers/translates_controller_test.rb +++ b/test/controllers/translates_controller_test.rb @@ -1,15 +1,15 @@ # frozen_string_literal: true -require "test_helper" +require 'test_helper' class TranslatesControllerTest < ActionDispatch::IntegrationTest - test "post valid transformation of sbJson to mdJson" do + test 'post valid transformation of sbJson to mdJson' do @translate = translates(:sbjson_to_mdjson) @file = File.read( File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}") ) - post "/translates", + post '/translates', params: { file: @file, reader: @translate.reader, @@ -19,13 +19,13 @@ class TranslatesControllerTest < ActionDispatch::IntegrationTest assert_response 200 end - test "post invalid transformation of fgdc to iso19115_3" do + test 'post invalid transformation of fgdc to iso19115_3' do @translate = translates(:fgdc_to_iso) @file = File.read( File.join(File.dirname(__FILE__), "../fixtures/#{@translate.file}") ) - post "/translates", + post '/translates', params: { file: @file, reader: @translate.reader, diff --git a/test/models/translate_test.rb b/test/models/translate_test.rb index e4c23dd..05e95bf 100644 --- a/test/models/translate_test.rb +++ b/test/models/translate_test.rb @@ -5,13 +5,17 @@ class TranslateTest < ActiveSupport::TestCase test 'convert fgdc to iso19115_3' do @translate = translates(:fgdc_to_iso) - @file = File.read(File.expand_path("../../fixtures/#{@translate.file}", __FILE__)) + @file = + File.read(File.expand_path("../../fixtures/#{@translate.file}", __FILE__)) @reader = @translate.reader @writer = @translate.writer - @md_return = ADIWG::Mdtranslator.translate( - file: @file, reader: @reader, writer: @writer - ) + @md_return = + ADIWG::Mdtranslator.translate( + file: @file, + reader: @reader, + writer: @writer + ) assert_not_nil(@md_return[:writerOutput]) end