From daa38cf62504127d3cbd9d4708af306c786fda95 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 11 Oct 2024 10:44:21 -0400 Subject: [PATCH] WIP some alma events stuff --- .gitignore | 1 + Gemfile | 1 + Gemfile.lock | 2 ++ alma_webhook.rb | 1 + lib/services.rb | 17 +++++++++++++++++ spec/lib/services_spec.rb | 15 +++++++++++++++ 6 files changed, 37 insertions(+) create mode 100644 lib/services.rb create mode 100644 spec/lib/services_spec.rb diff --git a/.gitignore b/.gitignore index 7b89388..17d4d30 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ sftp/ssh/* .irb_history .local/* .cache/ +.solargraph.yml diff --git a/Gemfile b/Gemfile index 6cc8d57..4c3007b 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ gem "faraday" gem "rackup" gem "sftp", github: "mlibrary/sftp" +gem "canister" group :development, :test do gem "pry" diff --git a/Gemfile.lock b/Gemfile.lock index 4d7f09d..f58ecce 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,6 +13,7 @@ GEM base64 (0.2.0) bigdecimal (3.1.6) byebug (11.1.3) + canister (0.9.2) climate_control (1.2.0) coderay (1.1.3) concurrent-ruby (1.2.3) @@ -146,6 +147,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + canister climate_control faraday pry diff --git a/alma_webhook.rb b/alma_webhook.rb index efda613..f8da796 100644 --- a/alma_webhook.rb +++ b/alma_webhook.rb @@ -5,6 +5,7 @@ require "faraday" require "byebug" if settings.environment == :development +require "./lib/services" require "./lib/message_validator" require "./lib/indexing_action" require "./lib/indexing_jobs_generator" diff --git a/lib/services.rb b/lib/services.rb new file mode 100644 index 0000000..a174b1f --- /dev/null +++ b/lib/services.rb @@ -0,0 +1,17 @@ +require "canister" +require "byebug" + +Services = Canister.new +S = Services + +S.register(:push_locations) do + ENV.fetch("PUSH_LOCATIONS", "").split("||") +end + +S.register(:push_locations?) do + !S.push_locations.empty? +end + +S.register(:project_root) do + File.absolute_path(File.join(__dir__, "..")) +end diff --git a/spec/lib/services_spec.rb b/spec/lib/services_spec.rb new file mode 100644 index 0000000..46df78e --- /dev/null +++ b/spec/lib/services_spec.rb @@ -0,0 +1,15 @@ +describe "Services" do + context ".push_locations" do + it "returns an array when there are items separated by ||" do + with_modified_env PUSH_LOCATIONS: "http://pushlocation:12000/example||http://pushlocation:12000/other_example" do + expect(S.push_locations).to contain_exactly("http://pushlocation:12000/example", "http://pushlocation:12000/other_example") + end + end + it "returns empty array if empty" do + with_modified_env PUSH_LOCATIONS: nil do + load(File.join(S.project_root, "lib", "services.rb")) + expect(S.push_locations).to eq([]) + end + end + end +end