Class: Html2rss::RequestService::LocalFileStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/html2rss/request_service/local_file_strategy.rb

Overview

Strategy to read a local HTML file.

Instance Method Summary collapse

Methods inherited from Strategy

#initialize

Constructor Details

This class inherits a constructor from Html2rss::RequestService::Strategy

Instance Method Details

#executeResponse

Executes the local file read.

Returns:

  • (Response)

    the mock response wrapped around the file contents

Raises:

  • (ArgumentError)

    if the local file path is missing

  • (Errno::ENOENT)

    if the file does not exist



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/html2rss/request_service/local_file_strategy.rb', line 14

def execute
  file_path = ctx.request[:local_file_path]
  raise ArgumentError, 'Local file path is required for local_file strategy' unless file_path
  raise Errno::ENOENT, "File not found: #{file_path}" unless File.exist?(file_path)

  body = File.read(file_path)
  Response.new(
    body:,
    headers: { 'content-type' => 'text/html; charset=utf-8' },
    url: ctx.url,
    status: 200
  )
end