Sha256: 1bc4de5e745befe9960882e13c78327eb94c80cf838206255e6d818ae2689cc7

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

module Lockness
  class SecretFile

    attr_reader :path

    def initialize
      @path = build_path
    end

    def exist?
      File.exist?(encrypted_path)
    end

    def unencrypted_path
      path.chomp('.enc')
    end

    def encrypted_path
      if path.ends_with?('.enc')
        path
      else
        "#{path}.enc"
      end
    end

    def read
      return unless exist?

      File.read(encrypted_path)
    end

    def save(encrypted_content)
      File.write(encrypted_path, encrypted_content)
    end

    private

    def build_path
      path_arg = ARGV.last

      if path_arg.starts_with?('/')
        path_arg
      else
        File.join(Dir.pwd, path_arg)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lockness-0.1.0 lib/lockness/secret_file.rb