class Svnx::IO::Element

Attributes

local[R]
path[R]
svn[R]

Public Class Methods

new(args = Hash.new) click to toggle source
# File lib/svnx/io/element.rb, line 27
def initialize args = Hash.new
  info "args: #{args.inspect}".color("438802")
  
  # svnurl = args[:svnurl]
  # fname  = args[:filename] || args[:file] # legacy
  # $$$ todo: map svnurl to SVNElement, and fname to FSElement

  @svn   = args[:svn] # || (args[:file] && SVNElement.new(:filename => args[:file]))
  @local = args[:local] && Pathname.new(args[:local]) # && PVN::FSElement.new(args[:local] || args[:file])
  @path  = args[:path]
  
  info "local: #{@local.inspect}"
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/svnx/io/element.rb, line 123
def <=> other
  @local <=> other.local
end
cat(args = Hash.new) click to toggle source
# File lib/svnx/io/element.rb, line 113
def cat args = Hash.new
  rev = args[:revision]
  catexec = Svnx::CatExec.new :path => @local, :revision => rev && rev.to_s, :use_cache => false
  catexec.output
end
directory?() click to toggle source
# File lib/svnx/io/element.rb, line 45
def directory?
  @local && @local.directory?
end
exist?() click to toggle source
# File lib/svnx/io/element.rb, line 41
def exist?
  @local && @local.exist?
end
file?() click to toggle source
# File lib/svnx/io/element.rb, line 49
def file?
  @local && @local.file?
end
find_by_status(status) click to toggle source
# File lib/svnx/io/element.rb, line 97
def find_by_status status
  statexec = Svnx::StatusExec.new path: @local, use_cache: false
  entries = statexec.entries

  entries.select do |entry|
    status.nil? || entry.status.to_s == status.to_s
  end.sort
end
find_entries(args = Hash.new) click to toggle source
# File lib/svnx/io/element.rb, line 71
def find_entries args = Hash.new
  revision = args[:revision]
  status = args[:status]
  
  if revision.nil?
    find_by_status status
  else
    find_in_log revision, status
  end
end
find_in_log(revision, action) click to toggle source
# File lib/svnx/io/element.rb, line 82
def find_in_log revision, action
  svninfo = get_info

  filter = svninfo.url.dup
  filter.slice! svninfo.root

  # we can't cache this, because we don't know if there has been an svn
  # update since the previous run:
  logexec = Svnx::LogExec.new path: @local, revision: revision, verbose: true, use_cache: false
  entries = logexec.entries
  
  act = action.kind_of?(Svnx::Action) ? action : Svnx::Action.new(action)
  entries.match act, filter
end
get_info(revision = nil) click to toggle source
# File lib/svnx/io/element.rb, line 53
def get_info revision = nil
  return nil unless in_svn?
  
  usepath = @local ? @local.to_path : @path
  inf = Svnx::Info::Command.new url: usepath, revision: revision
  inf.entry
end
in_svn?() click to toggle source
# File lib/svnx/io/element.rb, line 61
def in_svn?
  # svn status can only be a local path:
  if @local
    st = Svnx::StatusExec.new path: @local.to_path
    st.entries.size == 0 || st.entries[0].status.to_s != 'unversioned'
  else
    raise "cannot determine svn status without a local path; only target '#{@path}' defined"
  end
end
log_entries(args = Hash.new) click to toggle source
# File lib/svnx/io/element.rb, line 106
def log_entries args = Hash.new
  rev = args[:revision]
  # use_cache should be conditional on revision:
  logexec = Svnx::LogExec.new :path => @local, :revision => rev && rev.to_s, :verbose => true, :use_cache => false
  logexec.entries
end
to_s() click to toggle source
# File lib/svnx/io/element.rb, line 119
def to_s
  "svn => " + @svn.to_s + "; local => " + @local.to_s
end