Class: Stash::Harvester::SourceConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/stash/harvester/source_config.rb

Overview

Superclass for configuration of any data source.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_url:) ⇒ SourceConfig

Constructs a new SourceConfig with the specified properties.

Parameters:

  • source_url (URI, String)

    the base URL of the repository. *(Required)*

Raises:

  • (URI::InvalidURIError)

    if source_url is a string that is not a valid URI


16
17
18
# File 'lib/stash/harvester/source_config.rb', line 16

def initialize(source_url:)
  @source_uri = to_uri(source_url)
end

Instance Attribute Details

#source_uriURI (readonly)

Returns the base URL of the repository.

Returns:

  • (URI)

    the base URL of the repository.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stash/harvester/source_config.rb', line 8

class SourceConfig

  attr_reader :source_uri

  # Constructs a new +SourceConfig+ with the specified properties.
  #
  # @param source_url [URI, String] the base URL of the repository. *(Required)*
  # @raise [URI::InvalidURIError] if +source_url+ is a string that is not a valid URI
  def initialize(source_url:)
    @source_uri = to_uri(source_url)
  end

  # ------------------------------
  # Class methods

  # Parses the specified YAML string and passes it as a hash
  # with symbol keys to the implementation class initializer
  #
  # @return [SourceConfig] a new instance of this implementation class
  def self.from_yaml(yml)
    params = YAML.load(yml).map { |k, v| [k.to_sym, v] }.to_h
    new(params)
  end

  # ------------------------------
  # Private methods

  private

  def to_uri(url)
    (url.is_a? URI) ? url : URI.parse(url)
  end

end

Class Method Details

.from_yaml(yml) ⇒ SourceConfig

Parses the specified YAML string and passes it as a hash with symbol keys to the implementation class initializer

Returns:

  • (SourceConfig)

    a new instance of this implementation class


27
28
29
30
# File 'lib/stash/harvester/source_config.rb', line 27

def self.from_yaml(yml)
  params = YAML.load(yml).map { |k, v| [k.to_sym, v] }.to_h
  new(params)
end