Class: ClearcaseHelper::CCFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Executables

#cleartool

Constructor Details

#initialize(file_name, view) ⇒ CCFile

Returns a new instance of CCFile.



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

def initialize(file_name, view)
  @file = file_name
  @view = view
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



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

def file
  @file
end

#viewObject

Returns the value of attribute view.



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

def view
  @view
end

Instance Method Details

#<=>(other) ⇒ Object



119
120
121
# File 'lib/clearcase_helper/cc_file.rb', line 119

def <=>(other)
  self.to_s <=> other.to_s
end

#add!(options = {}) ⇒ Object



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

def add!(options={})
  parent = view.file_for(parent_dirname, options)
  if parent.is_view_only?
    parent.add!(options)
    parent.refresh_status(options)
  end

  parent.checkout!(options) unless parent.is_checkedout?
  success, stdout = cleartool("mkelem -c \"\" -ptime #{file.to_s.shellescape}", options)

  refresh_status(options)

  success
end

#checkin!(options = {}) ⇒ Object

Parameters:

  • Hash (Symbol => String)
    • :comment => ‘some comment’



98
99
100
101
102
103
104
105
# File 'lib/clearcase_helper/cc_file.rb', line 98

def checkin!(options={})
  comment = options[:comment] || ''
  success, stdout = cleartool("ci -c \"#{comment.shellescape}\" -identical -ptime #{self.to_s.shellescape}", options)

  refresh_status(options)

  success
end

#checkout!(options = {}) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/clearcase_helper/cc_file.rb', line 107

def checkout!(options={})
  success, stdout = cleartool("co -c \"\" -ptime -nwarn #{is_hijacked? ? '-usehijack' : ''} #{self.to_s.shellescape}", options)

  refresh_status(options)

  success
end

#directory?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/clearcase_helper/cc_file.rb', line 45

def directory?
  File.directory?(self.to_s)
end

#file?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/clearcase_helper/cc_file.rb', line 41

def file?
  File.file?(self.to_s)
end

#is_checkedin?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/clearcase_helper/cc_file.rb', line 29

def is_checkedin?
  short_status.strip.empty?
end

#is_checkedout?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/clearcase_helper/cc_file.rb', line 21

def is_checkedout?
  file.match /@@[^\s]+CHECKEDOUT/
end

#is_hijacked?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/clearcase_helper/cc_file.rb', line 13

def is_hijacked?
  file.match /\[hijacked\]/
end

#is_missing?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/clearcase_helper/cc_file.rb', line 25

def is_missing?
  file.match /\[loaded but missing\]/
end

#is_view_only?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/clearcase_helper/cc_file.rb', line 17

def is_view_only?
  !file.match /@@/
end

#parent_dirnameObject



49
50
51
# File 'lib/clearcase_helper/cc_file.rb', line 49

def parent_dirname
  File.dirname(self.to_s)
end

#refresh_status(options = {}) ⇒ CCFile

Refreshes state and returns self.

Returns:



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

def refresh_status(options={})
  success, stdout = cleartool("ls #{directory? ? '-directory' : ''} #{self.to_s.shellescape}", options)
  @file = stdout.strip

  self
end

#remove!(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/clearcase_helper/cc_file.rb', line 78

def remove!(options={})
  parent = view.file_for(parent_dirname, options)

  parent.checkout!(options) unless parent.is_checkedout?
  success, stdout = cleartool("rmname -c \"\" #{self.to_s.shellescape}", options)

  
  if success
    # no need to refresh file because this file does not exist anymore,
    # so just remove it from the identity map
    view.forget_file(self)
  else
    # do refresh status since deletion failed
    refresh_status(options)
  end

  success
end

#short_statusObject



33
34
35
36
37
38
39
# File 'lib/clearcase_helper/cc_file.rb', line 33

def short_status
  return 'HI' if is_hijacked?
  return 'CO' if is_checkedout?
  return '~ ' if is_missing?
  return '? ' if is_view_only?
  return '  '
end

#to_sObject



115
116
117
# File 'lib/clearcase_helper/cc_file.rb', line 115

def to_s
  @file_as_string ||= file.gsub(/@@.*$/, '')
end