From cdad4e00a9291d2876193e8d7ac8e87cd6ff112c Mon Sep 17 00:00:00 2001 From: Brooke Kuhlmann Date: Tue, 30 Jun 2026 13:15:49 -0600 Subject: [PATCH] Refactored extension parser as source Gives this a better name since we're _sourcing_ data from different data types. Plus, this isn't a callable object, only a collection of functions. Milestone: patch --- app/aspects/extensions/fetchers/client.rb | 12 ++++++------ app/aspects/extensions/{parser.rb => source.rb} | 4 ++-- .../extensions/{parser_spec.rb => source_spec.rb} | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename app/aspects/extensions/{parser.rb => source.rb} (92%) rename spec/app/aspects/extensions/{parser_spec.rb => source_spec.rb} (98%) diff --git a/app/aspects/extensions/fetchers/client.rb b/app/aspects/extensions/fetchers/client.rb index 15b7c3de..f1aa31f4 100644 --- a/app/aspects/extensions/fetchers/client.rb +++ b/app/aspects/extensions/fetchers/client.rb @@ -11,7 +11,7 @@ module Terminus # A client for processing HTTP requests. class Client include Deps[:http] - include Initable[parser: Extensions::Parser, special_header: "Accept"] + include Initable[source: Extensions::Source, special_header: "Accept"] include Dry::Monads[:result] def call input @@ -44,12 +44,12 @@ module Terminus def parse type, body case type - when %r(application/([[:alnum:]][\w!#&\-^$]*\+)?json) then parser.from_json body - when %r(image/.+) then parser.from_image body - when "text/csv" then parser.from_csv body - when "text/plain" then parser.from_text body + when %r(application/([[:alnum:]][\w!#&\-^$]*\+)?json) then source.from_json body + when %r(image/.+) then source.from_image body + when "text/csv" then source.from_csv body + when "text/plain" then source.from_text body when "text/xml", "application/xml", "application/rss+xml", "application/atom+xml" - parser.from_xml body + source.from_xml body else Failure "Unknown MIME Type: #{type}." end end diff --git a/app/aspects/extensions/parser.rb b/app/aspects/extensions/source.rb similarity index 92% rename from app/aspects/extensions/parser.rb rename to app/aspects/extensions/source.rb index 3807704d..9723eeff 100644 --- a/app/aspects/extensions/parser.rb +++ b/app/aspects/extensions/source.rb @@ -11,8 +11,8 @@ require "nori" module Terminus module Aspects module Extensions - # Parses supported data types into a hash for further processing. - module Parser + # Sources supported data types into a hash for further processing. + module Source extend Dry::Monads[:result] extend Functionable diff --git a/spec/app/aspects/extensions/parser_spec.rb b/spec/app/aspects/extensions/source_spec.rb similarity index 98% rename from spec/app/aspects/extensions/parser_spec.rb rename to spec/app/aspects/extensions/source_spec.rb index b14a27e5..aa4b561e 100644 --- a/spec/app/aspects/extensions/parser_spec.rb +++ b/spec/app/aspects/extensions/source_spec.rb @@ -2,7 +2,7 @@ require "hanami_helper" -RSpec.describe Terminus::Aspects::Extensions::Parser do +RSpec.describe Terminus::Aspects::Extensions::Source do subject(:parser) { described_class } describe ".from_csv" do