Class: Determinator::Retrieve::File

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/retrieve/file.rb

Overview

A class which loads features from files within the initialized folder

Instance Method Summary collapse

Constructor Details

#initialize(root:, serializer: Determinator::Serializers::JSON) ⇒ File

Returns a new instance of File.

Parameters:

  • :root (String, Pathname)

    The path to be used as the root to look in

  • :serializer (#load)

    A serializer which will take the string of the read file and return a Feature object.



9
10
11
12
# File 'lib/determinator/retrieve/file.rb', line 9

def initialize(root:, serializer: Determinator::Serializers::JSON )
  @root = Pathname.new(root)
  @serializer = serializer
end

Instance Method Details

#retrieve(feature_id) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/determinator/retrieve/file.rb', line 14

def retrieve(feature_id)
  feature = @root.join(feature_id.to_s)
  return unless feature.exist?
  @serializer.load(feature.read)
rescue => e
  Determinator.notice_error(e)
  nil
end