Sha256: 21a8d9942bad404c7bf97de879d18b7a95b962465741fe6a3b5b636f4c8f014c

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

require 'rbconfig'

module Gitenv

  class Config

    attr_reader :repos
    attr_reader :actions

    def initialize
      @context = Context.new self
      @repos, @actions = [], []
    end

    def repo path, &block
      @repos << Repository.new(path)
      @context.from path, &block
      self
    end

    def symlink file, options = {}
      raise "You must specify a repository or a source directory to symlink from" unless @context.from
      Symlink::Action.new(@context.dup, matcher(file), options).tap{ |a| @actions << a }
    end

    def copy file, options = {}
      raise "You must specify a repository or a source directory to copy from" unless @context.from
      Copy::Action.new(@context.dup, matcher(file), options).tap{ |a| @actions << a }
    end

    def all_files options = {}
      matcher :all_files, options
    end

    def dot_files options = {}
      matcher :dot_files, options
    end

    %w(from to).each do |m|
      define_method m do |*args,&block|
        @context.send *(args.unshift m), &block
        self
      end
    end

    def ignores
      @context.ignores
    end

    private

    def matcher file, options = {}
      options[:ignores] ||= @context.ignores.dup
      if file.kind_of? FilesMatcher
        file
      elsif file == :all_files
        AllFiles.new options
      elsif file == :dot_files
        DotFiles.new options
      else
        OneFile.new file, options
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gitenv-1.0.0 lib/gitenv/config.rb
gitenv-0.3.0 lib/gitenv/config.rb
gitenv-0.2.0 lib/gitenv/config.rb
gitenv-0.1.0 lib/gitenv/config.rb