Sha256: 5fc7db7db7714db4a5524c893d35a4822a846b8a8de248615576902d22cb2630

Contents?: true

Size: 1.27 KB

Versions: 11

Compression:

Stored size: 1.27 KB

Contents

module Dots
  module Persistence
    include Thor::Actions

    # Run through every file in +~/.dots/config+ and symlink them to
    # +~/.+.
    def link_dot_files
      Dir[File.expand_path("~/.dots/config/*")].each do |config_file|
        persist_dot_file config_file
      end
    end

    # Moves the given +~/.file+ to the repo, while saving its original
    # location. It then symlinks the new location to the old location
    # so applications will continue to run.
    def persist_dot_file file_name
      dot_file = Dots::DotFile.new file_name

      if dot_file.save
        say "#{dot_file} saved to DOTS!"
      else
        say "Error: #{dot_file} could not be symlinked:"
        dot_file.errors.full_messages.each { |msg| say "- #{msg}" }
      end
    end

    # Restores the given configuration file that's in the repo back
    # to an unremembered state. Deletes the symlink and places the
    # file back to its perceived original location in +~/.file+.
    def forget_dot_file file_name
      dot_file = Dots::DotFile.find file_name

      if dot_file.destroy
        say "#{dot_file} is no longer being persisted."
      else
        say "Error: #{dot_file} could not be forgotten:"
        dot_file.errors.full_messages.each { |msg| say "- #{msg}" }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
zsh_dots-0.6.5 lib/ruby/dots/persistence.rb
zsh_dots-0.6.3 lib/ruby/dots/persistence.rb
zsh_dots-0.6.2 lib/ruby/dots/persistence.rb
zsh_dots-0.6.0 lib/ruby/dots/persistence.rb
zsh_dots-0.5.9 lib/ruby/dots/persistence.rb
zsh_dots-0.5.8 lib/ruby/dots/persistence.rb
zsh_dots-0.5.7 lib/ruby/dots/persistence.rb
zsh_dots-0.5.6 lib/ruby/dots/persistence.rb
zsh_dots-0.5.5 lib/ruby/dots/persistence.rb
zsh_dots-0.5.4 lib/ruby/dots/persistence.rb
zsh_dots-0.5.3 lib/ruby/dots/persistence.rb