Class: SVNx::IO::Element
- Inherits:
-
Object
- Object
- SVNx::IO::Element
- Includes:
- Comparable, Logue::Loggable
- Defined in:
- lib/svnx/io/element.rb
Overview
An element unites an svn element and a file/directory (at least one of which should exist).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#local ⇒ Object
readonly
Returns the value of attribute local.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#svn ⇒ Object
readonly
Returns the value of attribute svn.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #cat(args = Hash.new) ⇒ Object
- #directory? ⇒ Boolean
- #exist? ⇒ Boolean
- #file? ⇒ Boolean
- #find_by_status(status) ⇒ Object
- #find_entries(args = Hash.new) ⇒ Object
- #find_in_log(revision, action) ⇒ Object
- #get_info(revision = nil) ⇒ Object
- #in_svn? ⇒ Boolean
-
#initialize(args = Hash.new) ⇒ Element
constructor
A new instance of Element.
- #log_entries(args = Hash.new) ⇒ Object
- #to_s ⇒ Object
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 |
# 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 |
Instance Attribute Details
#local ⇒ Object (readonly)
Returns the value of attribute local.
25 26 27 |
# File 'lib/svnx/io/element.rb', line 25 def local @local end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
24 25 26 |
# File 'lib/svnx/io/element.rb', line 24 def path @path end |
#svn ⇒ Object (readonly)
Returns the value of attribute svn.
23 24 25 |
# File 'lib/svnx/io/element.rb', line 23 def svn @svn end |
Instance Method Details
#<=>(other) ⇒ Object
123 124 125 |
# File 'lib/svnx/io/element.rb', line 123 def <=> other @local <=> other.local end |
#cat(args = Hash.new) ⇒ Object
113 114 115 116 117 |
# 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? ⇒ Boolean
45 46 47 |
# File 'lib/svnx/io/element.rb', line 45 def directory? @local && @local.directory? end |
#exist? ⇒ Boolean
41 42 43 |
# File 'lib/svnx/io/element.rb', line 41 def exist? @local && @local.exist? end |
#file? ⇒ Boolean
49 50 51 |
# File 'lib/svnx/io/element.rb', line 49 def file? @local && @local.file? end |
#find_by_status(status) ⇒ Object
97 98 99 100 101 102 103 104 |
# 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) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# 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) ⇒ Object
53 54 55 56 57 58 59 |
# 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::InfoExec.new path: usepath, revision: revision inf.entry end |
#in_svn? ⇒ Boolean
61 62 63 64 65 66 67 68 69 |
# 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) ⇒ Object
106 107 108 109 110 111 |
# 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 ⇒ Object
119 120 121 |
# File 'lib/svnx/io/element.rb', line 119 def to_s "svn => " + @svn.to_s + "; local => " + @local.to_s end |