Class: ClearcaseHelper::CCFile
- Inherits:
-
Object
- Object
- ClearcaseHelper::CCFile
- Includes:
- Executables
- Defined in:
- lib/clearcase_helper/cc_file.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add!(options = {}) ⇒ Object
- #checkin!(options = {}) ⇒ Object
- #checkout!(options = {}) ⇒ Object
- #directory? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(file_name, view) ⇒ CCFile
constructor
A new instance of CCFile.
- #is_checkedin? ⇒ Boolean
- #is_checkedout? ⇒ Boolean
- #is_hijacked? ⇒ Boolean
- #is_missing? ⇒ Boolean
- #is_view_only? ⇒ Boolean
- #parent_dirname ⇒ Object
-
#refresh_status(options = {}) ⇒ CCFile
Refreshes state and returns self.
- #remove!(options = {}) ⇒ Object
- #short_status ⇒ Object
- #to_s ⇒ Object
Methods included from Executables
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
#file ⇒ Object
Returns the value of attribute file.
5 6 7 |
# File 'lib/clearcase_helper/cc_file.rb', line 5 def file @file end |
#view ⇒ Object
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!(={}) parent = view.file_for(parent_dirname, ) if parent.is_view_only? parent.add!() parent.refresh_status() end parent.checkout!() unless parent.is_checkedout? success, stdout = cleartool("mkelem -c \"\" -ptime #{file.to_s.shellescape}", ) refresh_status() success end |
#checkin!(options = {}) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/clearcase_helper/cc_file.rb', line 98 def checkin!(={}) comment = [:comment] || '' success, stdout = cleartool("ci -c \"#{comment.shellescape}\" -identical -ptime #{self.to_s.shellescape}", ) refresh_status() success end |
#checkout!(options = {}) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/clearcase_helper/cc_file.rb', line 107 def checkout!(={}) success, stdout = cleartool("co -c \"\" -ptime -nwarn #{is_hijacked? ? '-usehijack' : ''} #{self.to_s.shellescape}", ) refresh_status() success end |
#directory? ⇒ Boolean
45 46 47 |
# File 'lib/clearcase_helper/cc_file.rb', line 45 def directory? File.directory?(self.to_s) end |
#file? ⇒ Boolean
41 42 43 |
# File 'lib/clearcase_helper/cc_file.rb', line 41 def file? File.file?(self.to_s) end |
#is_checkedin? ⇒ Boolean
29 30 31 |
# File 'lib/clearcase_helper/cc_file.rb', line 29 def is_checkedin? short_status.strip.empty? end |
#is_checkedout? ⇒ Boolean
21 22 23 |
# File 'lib/clearcase_helper/cc_file.rb', line 21 def is_checkedout? file.match /@@[^\s]+CHECKEDOUT/ end |
#is_hijacked? ⇒ Boolean
13 14 15 |
# File 'lib/clearcase_helper/cc_file.rb', line 13 def is_hijacked? file.match /\[hijacked\]/ end |
#is_missing? ⇒ 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
17 18 19 |
# File 'lib/clearcase_helper/cc_file.rb', line 17 def is_view_only? !file.match /@@/ end |
#parent_dirname ⇒ Object
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.
56 57 58 59 60 61 |
# File 'lib/clearcase_helper/cc_file.rb', line 56 def refresh_status(={}) success, stdout = cleartool("ls #{directory? ? '-directory' : ''} #{self.to_s.shellescape}", ) @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!(={}) parent = view.file_for(parent_dirname, ) parent.checkout!() unless parent.is_checkedout? success, stdout = cleartool("rmname -c \"\" #{self.to_s.shellescape}", ) 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() end success end |
#short_status ⇒ Object
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_s ⇒ Object
115 116 117 |
# File 'lib/clearcase_helper/cc_file.rb', line 115 def to_s @file_as_string ||= file.gsub(/@@.*$/, '') end |