Sha256: 86643c4617111aacc656a876be7cbc9c2b5feb8d2a8499d3c2733d166590d890

Contents?: true

Size: 1004 Bytes

Versions: 14

Compression:

Stored size: 1004 Bytes

Contents

module Ro
  class Root < ::String
    def initialize(root)
      super(Ro.realpath(root.to_s))
    ensure
      raise ArgumentError.new("root=#{ root.inspect }") if root.nil?
      raise ArgumentError.new("root=#{ root.inspect }") unless test(?d, root)
    end

    def root
      self
    end

    def nodes
      Node::List.new(root) do |list|
        node_directories do |path|
          list.load(path)
        end
      end
    end

    def directories(&block)
      Dir.glob(File.join(root, '*/'), &block)
    end

    def node_directories(&block)
      Dir.glob(File.join(root, '*/*/'), &block)
    end

    def git
      @git ||= Git.new(self)
    end

    def patch(*args, &block)
      git.patch(*args, &block)
    end

    def dotdir
      File.join(self, '.ro')
    end

    def lockpath
      File.join(dotdir, 'lock')
    end

    def lock(&block)
      FileUtils.mkdir_p(File.dirname(lockpath))
      @lock ||= Lock.new(lockpath)
      block ? @lock.lock(&block) : @lock
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ro-1.4.4 lib/ro/root.rb
ro-1.4.3 lib/ro/root.rb
ro-1.4.2 lib/ro/root.rb
ro-1.4.1 lib/ro/root.rb
ro-1.4.0 lib/ro/root.rb
ro-1.3.8 lib/ro/root.rb
ro-1.3.7 lib/ro/root.rb
ro-1.3.6 lib/ro/root.rb
ro-1.3.5 lib/ro/root.rb
ro-1.3.4 lib/ro/root.rb
ro-1.3.3 lib/ro/root.rb
ro-1.3.2 lib/ro/root.rb
ro-1.3.1 lib/ro/root.rb
ro-1.2.0 lib/ro/root.rb