Class: Source::FileRepository

Inherits:
Object
  • Object
show all
Includes:
Repository
Defined in:
lib/file_repository.rb

Overview

FileRepository is a struct that implements the Repository interface for handling configuration data stored in a YAML file.

Instance Attribute Summary collapse

Attributes included from Repository

#data, #lock, #name

Instance Method Summary collapse

Methods included from Repository

#get_data, #get_name

Constructor Details

#initialize(name:, path:) ⇒ FileRepository

Returns a new instance of FileRepository.



14
15
16
17
# File 'lib/file_repository.rb', line 14

def initialize(name:, path:)
  super(name: name)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/file_repository.rb', line 12

def path
  @path
end

Instance Method Details

#refreshObject

Refresh reads the YAML file, unmarshal it into the data map.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/file_repository.rb', line 22

def refresh
  @lock.synchronize do
    # Read the YAML file
    data = File.read(@path)
    # Unmarshal the YAML data into the data map
    @data = YAML.safe_load(data)

    # Store the raw data of the YAML file
    @raw_data = data
  end
end