Class: ClearcaseHelper::View

Inherits:
Object
  • Object
show all
Includes:
Executables
Defined in:
lib/clearcase_helper/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Executables

#cleartool

Constructor Details

#initialize(view_path) ⇒ View

Returns a new instance of View.



8
9
10
# File 'lib/clearcase_helper/view.rb', line 8

def initialize(view_path)
  @view_path = view_path
end

Instance Attribute Details

#identity_mapObject (readonly)

Returns the value of attribute identity_map.



6
7
8
# File 'lib/clearcase_helper/view.rb', line 6

def identity_map
  @identity_map
end

#view_pathObject (readonly)

Returns the value of attribute view_path.



5
6
7
# File 'lib/clearcase_helper/view.rb', line 5

def view_path
  @view_path
end

Instance Method Details

#add_view_only_files!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



110
111
112
113
114
# File 'lib/clearcase_helper/view.rb', line 110

def add_view_only_files!(options={})
  view_only_files(false, options.merge(:nostdout => true, :noop => false)).sort.each do |file|
    file.add!(options)
  end
end

#all_files_with_status(refresh = false, options = {}) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/clearcase_helper/view.rb', line 56

def all_files_with_status(refresh=false, options={})
  show_short = !options[:long]

  files(refresh, options).reject {|file| show_short and file.is_checkedin?}.collect do |file|
    "#{file.short_status} #{file}"
  end
end

#checkedout_files(refresh = false, options = {}) ⇒ Object



48
49
50
# File 'lib/clearcase_helper/view.rb', line 48

def checkedout_files(refresh=false, options={})
  files(refresh, options).select {|f| f.is_checkedout?}
end

#checkin_checkedout!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :comment => ‘some comment’, :debug => boolean, :noop => :boolean



88
89
90
91
92
# File 'lib/clearcase_helper/view.rb', line 88

def checkin_checkedout!(options={})
  checkedout_files(false, options.merge(:nostdout => true, :noop => false)).each do |file|
    file.checkin!(options)
  end
end

#checkin_hijacked!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



102
103
104
105
106
107
# File 'lib/clearcase_helper/view.rb', line 102

def checkin_hijacked!(options={})
  hijacked_files(false, options.merge(:nostdout => true, :noop => false)).each do |file|
    file.checkout!(options)
    file.checkin!(options)
  end
end

#checkout_highjacked!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



95
96
97
98
99
# File 'lib/clearcase_helper/view.rb', line 95

def checkout_highjacked!(options={})
  hijacked_files(false, options.merge(:nostdout => true, :noop => false)).each do |file|
    file.checkout!(options)
  end
end

#file_for(file, options = {}) ⇒ CCFile

Parameters:

  • file (String, CCFile)

    to get from the identity map. If the file is missing a new instance is added to the map and returned.

Returns:



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

def file_for(file, options={})
  file = file.to_s.strip

  cc_file = @identity_map[file]

  if cc_file.nil? && !file.empty?
    cc_file = @identity_map[file] = CCFile.new(file, self).refresh_status(options)
  end

  cc_file
end

#files(refresh = false, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clearcase_helper/view.rb', line 12

def files(refresh=false, options={})
  if @files and !refresh
    return @files
  end

  success, stdout = cleartool("ls -recurse #{@view_path.shellescape}", options)

  # load excludes from .ccignore
  ccignore_file = File.join(@view_path,'.ccignore')
  ccignore = if File.exist?(ccignore_file)
               File.readlines(ccignore_file).map {|ignore| ignore.strip}
             else
               %w(\.hg|\.git|\.svn)
             end

  raw_files = stdout.split(/\n/)
  raw_files.reject! do |f|
    ccignore.any? do |ignore|
      f.match(/#{ignore}/)
    end
  end # filter excluded files / folders

  @files = raw_files.map {|f| CCFile.new(f, self)}
  @identity_map = @files.inject({}) {|memo, file| memo[file.to_s] = file; memo}

  @files
end

#forget_file(file) ⇒ CCFile

Removes given file from this views identity map. Used by the remove! file action to cleanup view state on success.

Parameters:

  • file (String, CCFile)

    to forget in the identity map.

Returns:

  • (CCFile)

    the file that has been removed from the identity map.



83
84
85
# File 'lib/clearcase_helper/view.rb', line 83

def forget_file(file)
  @identity_map.delete(file)
end

#hijacked_files(refresh = false, options = {}) ⇒ Object



44
45
46
# File 'lib/clearcase_helper/view.rb', line 44

def hijacked_files(refresh=false, options={})
  files(refresh, options).select {|f| f.is_hijacked?}
end

#make_label(label, options = {}) ⇒ Object

Parameters:

  • String

    label - the label name to apply recursively to all files in actual view path

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



132
133
134
135
# File 'lib/clearcase_helper/view.rb', line 132

def make_label(label, options={})
  comment = options[:comment] || ''
  cleartool("mklabel -c \"#{comment.shellescape}\" -recurse #{label.shellescape} #{@view_path.shellescape}", options)
end

#make_label_type(label, options = {}) ⇒ Object

Parameters:

  • String

    label - the label type name to create

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



125
126
127
128
# File 'lib/clearcase_helper/view.rb', line 125

def make_label_type(label, options={})
  comment = (options[:comment] || '') + ": #{@view_path}"
  cleartool("mklbtype -c \"#{comment.shellescape}\" #{label.shellescape}", options)
end

#missing_files(refresh = false, options = {}) ⇒ Object



52
53
54
# File 'lib/clearcase_helper/view.rb', line 52

def missing_files(refresh=false, options={})
  files(refresh, options).select {|f| f.is_missing?}
end

#remove_missing_files!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :debug => boolean, :noop => :boolean



117
118
119
120
121
# File 'lib/clearcase_helper/view.rb', line 117

def remove_missing_files!(options={})
  missing_files(false, options.merge(:nostdout => true, :noop => false)).sort.reverse.each do |file|
    file.remove!(options)
  end
end

#view_only_files(refresh = false, options = {}) ⇒ Object



40
41
42
# File 'lib/clearcase_helper/view.rb', line 40

def view_only_files(refresh=false, options={})
  files(refresh, options).select {|f| f.is_view_only?}
end