Sha256: 33865b43ce8087ba96b5ead7d5288c99b9e18cb35da6cd7e35750b3608bfc70e

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'dotter/utilities'
require 'dotter/configuration'
require 'dotter/gitrepo'
require 'dotter/foreigngitrepo'
module Dotter
  class Package
    include Utilities
    def initialize(name)
      @name = name
      @config = Configuration.new
      @our_config = @config.package_config(@name)
      if self.tracked?
        unless self.foreign?
          @repo = GitRepo.new(name)
        else
          @repo = ForeignGitRepo.new(name)
        end
      end
    end

    def stow
      go_to_dotfiles
      returned_output = `stow -v #{@name}`
      @config.set_state(@name, 'stowed')
      returned_output
    end

    def unstow
      go_to_dotfiles
      returned_output = `stow -Dv #{@name}`
      @config.set_state(@name, 'unstowed')
      returned_output
    end

    def track
      @repo = GitRepo.new(@name, true)
      @config.track(@name)
    end

    def update
      go_to_dotfiles
      @repo.update if self.foreign?
      returned_output = `stow -Rv #{@name}`
    end

    def stowed?
      @our_config['state'] == 'stowed'
    end

    def unstowed?
      !self.stowed?
    end

    def tracked?
      @our_config['tracked']
    end

    def untracked?
      !self.tracked?
    end

    def foreign?
      @our_config['type'] == 'git_repo'
    end

    def to_s
      @name
    end

    def public?
      @our_config['public'] == true
    end

    def private?
      !self.public?
    end
    attr_reader :name
    attr_accessor :config
    attr_reader :repo
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dotter_dotfiles-0.4.0 lib/dotter/package.rb
dotter_dotfiles-0.3.0 lib/dotter/package.rb