Sha256: 35c355cce366052bf461b50a470f1d6183c82f9983ccb288beda439c706f10ce

Contents?: true

Size: 743 Bytes

Versions: 1

Compression:

Stored size: 743 Bytes

Contents

# frozen_string_literal: true

require 'hanami/interactor'
require 'json'

module Umwelt::Abstract::File
  class Restore < Umwelt::Abstract::Interactor
    expose :struct

    def initialize(path: '.umwelt',
                   mapper: Struct)
      @path = path
      @mapper = mapper
    end

    private

    def read(path)
      path.read
    rescue Errno::ENOENT
      error! "Failed reading #{path}"
    end

    def parse(str)
      JSON.parse(str, symbolize_names: true)
    rescue JSON::ParserError
      error! "Failed JSON parsing #{self.class.name}"
    end

    def struct(struct_hash)
      prove(
        @mapper.new.call(struct_hash)
      ).struct
    end

    def umwelt_root_path
      Pathname.pwd / @path
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
umwelt-0.2 lib/umwelt/abstract/file/restore.rb