Class: Bhook::SourceConfig

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/bhook/source_config.rb

Overview

Valid keys:

  • website

    • link to place in the footer

  • exclude

    • list of .md file paths relative to config files

Constant Summary collapse

BHOOK_CONFIG_FILE =
T.let('.bhook.yml', String)
WEBSITE_KEY =
T.let('website', String)
EXCLUDE_KEY =
T.let('exclude', String)

Instance Method Summary collapse

Constructor Details

#initialize(root_dir_path, additional_options = {}) ⇒ SourceConfig

Returns a new instance of SourceConfig.



18
19
20
21
22
23
24
# File 'lib/bhook/source_config.rb', line 18

def initialize(root_dir_path, additional_options = {})
  config_file_path = root_dir_path.join(BHOOK_CONFIG_FILE)
  config = load_config(config_file_path).merge(additional_options)
  @root_dir_path = root_dir_path
  @website_url = T.let(config[WEBSITE_KEY], T.nilable(String))
  @excluded_files = T.let(parse_excluded_files(config[EXCLUDE_KEY] || []), T::Array[Pathname])
end

Instance Method Details

#excluded?(pathname) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/bhook/source_config.rb', line 35

def excluded?(pathname)
  @excluded_files.include?(pathname)
end

#website_url_for(src_file_path, src_file_sha) ⇒ Object



27
28
29
30
31
32
# File 'lib/bhook/source_config.rb', line 27

def website_url_for(src_file_path, src_file_sha)
  return unless @website_url && src_file_sha

  relative_file_path = src_file_path.relative_path_from(@root_dir_path)
  File.join(@website_url, src_file_sha, relative_file_path)
end