Class: PVN::IO::Element

Inherits:
Object
  • Object
show all
Includes:
Logue::Loggable
Defined in:
lib/pvn/io/element.rb

Overview

An element unites an svn element and a file/directory (at least one of which should exist).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = Hash.new) ⇒ Element

Returns a new instance of Element.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/pvn/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] && PVN::FSElement.new(args[:local] || args[:file])
  @path  = args[:path]
  
  info "local: #{@local.inspect}"

  @svnelement = SVNx::IO::Element.new args
  info "@svnelement: #{@svnelement}"
end

Instance Attribute Details

#localObject (readonly)

Returns the value of attribute local.



25
26
27
# File 'lib/pvn/io/element.rb', line 25

def local
  @local
end

#svnObject (readonly)

Returns the value of attribute svn.



24
25
26
# File 'lib/pvn/io/element.rb', line 24

def svn
  @svn
end

Instance Method Details

#<=>(other) ⇒ Object



113
114
115
# File 'lib/pvn/io/element.rb', line 113

def <=> other
  @svn <=> other.svn
end

#cat(revision, use_cache = false) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/pvn/io/element.rb', line 88

def cat revision, use_cache = false
  info "@local: #{@local}"
  info "@path: #{@path}"
  info "@svn: #{@svn}"
  
  path = (@local || @path || @svn).dup
  info "path: #{path.to_s}"
  if revision && revision != :working_copy
    path << '@' << revision.to_s
  end
  info "path: #{path}"
  catexec = SVNx::CatExec.new path: path, revision: nil, use_cache: use_cache
  catexec.output
end

#directory?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/pvn/io/element.rb', line 48

def directory?
  @svnelement.directory?
end

#exist?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pvn/io/element.rb', line 44

def exist?
  @local && @local.exist?
end

#file?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pvn/io/element.rb', line 52

def file?
  @svnelement.file?
end

#find_entries(revision, status) ⇒ Object

returns a set of entries matching status for the given revision



84
85
86
# File 'lib/pvn/io/element.rb', line 84

def find_entries revision, status
  @svnelement.find_in_log revision, status
end

#find_files_by_status(status = nil) ⇒ Object

returns a set of local files that have the given status/action



104
105
106
# File 'lib/pvn/io/element.rb', line 104

def find_files_by_status status = nil
  @svnelement.find_by_status status
end

#get_info(revision = nil) ⇒ Object



56
57
58
59
60
# File 'lib/pvn/io/element.rb', line 56

def get_info revision = nil
  usepath = @local || @path
  inf = SVNx::InfoExec.new path: usepath, revision: revision
  inf.entry
end

#has_revision?(rev) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pvn/io/element.rb', line 66

def has_revision? rev
  # was there a revision then?
  begin
    get_info rev
    true
  rescue => e
    puts "e: #{e}"
    raise e
    # false
  end
end

#logentries(revision) ⇒ Object

returns log entries



109
110
111
# File 'lib/pvn/io/element.rb', line 109

def logentries revision
  @svnelement.log_entries :revision => revision
end

#repo_rootObject



62
63
64
# File 'lib/pvn/io/element.rb', line 62

def repo_root
  get_info.root
end

#status_to_symbol(status) ⇒ Object



78
79
80
81
# File 'lib/pvn/io/element.rb', line 78

def status_to_symbol status
  # add a ? if not there already
  (status.to_s.sub(%r{\??$}, '?')).to_sym
end

#to_sObject



117
118
119
# File 'lib/pvn/io/element.rb', line 117

def to_s
  "svn => " + @svn.to_s + "; local => " + @local.to_s
end