Module: IssueScheduler

Defined in:
lib/issue_scheduler.rb,
lib/issue_scheduler/config.rb,
lib/issue_scheduler/version.rb,
lib/issue_scheduler/issue_template.rb

Overview

A module to encapsulate the Issue Scheduler functionality

Defined Under Namespace

Classes: Config, IssueTemplate

Constant Summary collapse

VERSION =

The version of the Issue Scheduler gem

'0.1.1'

Class Method Summary collapse

Class Method Details

.lib_dirString

Return the directory where the Issue Scheduler code is located

Examples:

IssueScheduler.lib_dir #=> '/path/to/issue_scheduler'

Returns:

  • (String)

    the directory where the Issue Scheduler code is located



18
19
20
# File 'lib/issue_scheduler.rb', line 18

def self.lib_dir
  File.join(__dir__, 'issue_scheduler')
end

.load_yaml(file_name) ⇒ Hash

Reads the contents of the given YAML file

Examples:

File.write('data.yaml', <<~YAML)
  username: user
  password: pass
YAML
IssueScheduler.read_yaml('data.yaml') #=> { username: 'user', password: 'pass' }

Parameters:

  • file_name (String)

    the file name to read

Returns:

  • (Hash)

    the parsed YAML object as a Hash

Raises:

  • (RuntimeError)

    if the file cannot be read or the parsed YAML is not valid or not an object



64
65
66
67
68
69
# File 'lib/issue_scheduler.rb', line 64

def self.load_yaml(file_name)
  yaml_string = File.read(file_name)
  parse_yaml(yaml_string)
rescue Errno::ENOENT => e
  raise "Error reading YAML file: #{e.message}"
end

.parse_yaml(yaml_string) ⇒ Hash

Parses the given YAML string

Examples:

yaml = <<~YAML
  username: user
  password: pass
YAML
IssueScheduler.parse_yaml(yaml) #=> { username: 'user', password: 'pass' }

Parameters:

  • yaml_string (String)

    the YAML object to parse

Returns:

  • (Hash)

    the parsed YAML object as a Hash

Raises:

  • (RuntimeError)

    if the YAML is not valid or is not an object



37
38
39
40
41
42
43
44
# File 'lib/issue_scheduler.rb', line 37

def self.parse_yaml(yaml_string)
  yaml_options = { permitted_classes: [Symbol, Date], aliases: true, symbolize_names: true }
  YAML.safe_load(yaml_string, **yaml_options).tap do |yaml|
    raise 'YAML is not an object' unless yaml.is_a?(Hash)
  end
rescue Psych::SyntaxError => e
  raise "YAML is not valid: #{e.message}"
end