Sha256: 015231f686b5c2d60489029d8f2eb85008b8ffc447c3f2e59033b73cf44f003a

Contents?: true

Size: 787 Bytes

Versions: 18

Compression:

Stored size: 787 Bytes

Contents

require 'pathname'

module Determinator
  module Retrieve
    # A class which loads features from files within the initialized folder
    class File
      # @param :root [String,Pathname] The path to be used as the root to look in
      # @param :serializer [#load] A serializer which will take the string of the read file and return a Feature object.
      def initialize(root:, serializer: Determinator::Serializers::JSON )
        @root = Pathname.new(root)
        @serializer = serializer
      end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
determinator-2.9.3 lib/determinator/retrieve/file.rb
determinator-2.9.2 lib/determinator/retrieve/file.rb
determinator-2.9.1 lib/determinator/retrieve/file.rb
determinator-2.9.0 lib/determinator/retrieve/file.rb
determinator-2.8.0 lib/determinator/retrieve/file.rb
determinator-2.7.1 lib/determinator/retrieve/file.rb
determinator-2.7.0 lib/determinator/retrieve/file.rb
determinator-2.6.0 lib/determinator/retrieve/file.rb
determinator-2.5.4 lib/determinator/retrieve/file.rb
determinator-2.5.3 lib/determinator/retrieve/file.rb
determinator-2.5.2 lib/determinator/retrieve/file.rb
determinator-2.5.1 lib/determinator/retrieve/file.rb
determinator-2.5.0 lib/determinator/retrieve/file.rb
determinator-2.4.4 lib/determinator/retrieve/file.rb
determinator-2.4.3 lib/determinator/retrieve/file.rb
determinator-2.4.2 lib/determinator/retrieve/file.rb
determinator-2.4.0 lib/determinator/retrieve/file.rb
determinator-2.3.1 lib/determinator/retrieve/file.rb