mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
Reference in New Issue
Block a user