Class: Html2rss::FeedPipeline::StrategyPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/feed_pipeline/strategy_plan.rb

Overview

Feed-level request plan: :auto (fallback chain) or a concrete transport strategy.

RequestService executes concrete adapters only. :auto is resolved here before any session or adapter call — plan vs transport locality.

Defined Under Namespace

Classes: Auto, Concrete

Constant Summary collapse

AUTO_NAME =

Symbol used in config / configure for the auto plan.

:auto

Class Method Summary collapse

Class Method Details

.accepted_namesArray<Symbol>

Returns accepted plan names (+:auto+ plus registered strategies).

Returns:

  • (Array<Symbol>)

    accepted plan names (+:auto+ plus registered strategies)



58
59
60
# File 'lib/html2rss/feed_pipeline/strategy_plan.rb', line 58

def accepted_names
  [AUTO_NAME, *RequestService.strategy_names.map(&:to_sym)].uniq
end

.resolve(name) ⇒ Auto, Concrete

Returns resolved feed-level plan.

Parameters:

  • name (Symbol, String)

    config or configure strategy value

Returns:

Raises:

  • (ArgumentError)

    when name is neither :auto nor a registered strategy



33
34
35
36
37
38
39
40
41
42
# File 'lib/html2rss/feed_pipeline/strategy_plan.rb', line 33

def resolve(name)
  normalized = name.to_sym
  return Auto.new if normalized == AUTO_NAME

  unless RequestService.strategy_registered?(normalized)
    raise ArgumentError, "unknown strategy plan: #{name.inspect}"
  end

  Concrete.new(strategy: normalized)
end

.valid?(name) ⇒ Boolean

Returns whether name is a valid feed-level strategy plan.

Parameters:

  • name (Symbol, String, nil)

    candidate plan name

Returns:

  • (Boolean)

    whether name is a valid feed-level strategy plan



47
48
49
50
51
52
53
54
# File 'lib/html2rss/feed_pipeline/strategy_plan.rb', line 47

def valid?(name)
  return false unless name.is_a?(Symbol) || name.is_a?(String)

  resolve(name)
  true
rescue ArgumentError
  false
end