Sha256: 2e6dcbd30267727fa25754415e8a555809fcb2efff4a6fc9ecb77a8f80c7eb49

Contents?: true

Size: 787 Bytes

Versions: 7

Compression:

Stored size: 787 Bytes

Contents

module CurrencyRate
  class FileStorage
    attr_reader   :path
    attr_accessor :serializer

    def initialize(path = nil, serializer: nil)
      @path       = path || CurrencyRate.configuration.file_storage[:path]
      @serializer = serializer || Storage::YAMLSerializer.new
    end

    def read(exchange_name)
      path = path_for exchange_name.downcase
      @serializer.deserialize File.read(path)
    rescue StandardError => e
      CurrencyRate.logger.error(e)
      nil
    end

    def write(exchange_name, data = "")
      File.write path_for(exchange_name.downcase), @serializer.serialize(data)
    rescue StandardError => e
      CurrencyRate.logger.error(e)
    end

    def path_for(exchange_name)
      File.join @path, "#{exchange_name}_rates.yml"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
currency-rate-1.6.1 lib/storage/file_storage.rb
currency-rate-1.6.0 lib/storage/file_storage.rb
currency-rate-1.5.4 lib/storage/file_storage.rb
currency-rate-1.5.3 lib/storage/file_storage.rb
currency-rate-1.5.2 lib/storage/file_storage.rb
currency-rate-1.5.1 lib/storage/file_storage.rb
currency-rate-1.4.1 lib/storage/file_storage.rb