Class: RIM::RimInfo
- Inherits:
-
Object
- Object
- RIM::RimInfo
- Defined in:
- lib/rim/rim_info.rb
Overview
RimInfo is RIM’s per module information written to project gits. The user is not meant to modify these files directly: Files are protected by a checksum an will become invalid if modified.
Example:
4759302048574720930432049375757593827561
remote_url: ssh://some/url/to/git/repo
revision: 8347982374198379842984562095637243593092
rev_name: mymod-1.2.3
upstream: trunk
ignores: CMakeLists.txt,*.arxml
checksum: 9584872389474857324485873627894494726222
rev_name is a symbolic name for revision
ignores is a comma separated list of file patterns to be ignored
Constant Summary collapse
- InfoFileName =
".riminfo"
- AttrsDef =
[ :remote_url, :revision_sha1, :target_revision, :ignores, :checksum ]
Class Method Summary collapse
Instance Method Summary collapse
- #dirty? ⇒ Boolean
- #from_dir(dir) ⇒ Object
- #from_s(content) ⇒ Object
- #to_dir(dir) ⇒ Object
- #to_s ⇒ Object
Class Method Details
.exists?(dir) ⇒ Boolean
39 40 41 |
# File 'lib/rim/rim_info.rb', line 39 def self.exists?(dir) File.exist?(info_file(dir)) end |
.from_dir(dir) ⇒ Object
43 44 45 46 47 |
# File 'lib/rim/rim_info.rb', line 43 def self.from_dir(dir) mi = self.new mi.from_dir(dir) mi end |
.from_s(content) ⇒ Object
49 50 51 52 53 |
# File 'lib/rim/rim_info.rb', line 49 def self.from_s(content) mi = self.new mi.from_s(content) mi end |
Instance Method Details
#dirty? ⇒ Boolean
55 56 57 |
# File 'lib/rim/rim_info.rb', line 55 def dirty? @dirty end |
#from_dir(dir) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rim/rim_info.rb', line 84 def from_dir(dir) file = RimInfo.info_file(dir) if File.exist?(file) content = nil File.open(file, "rb") do |f| content = f.read end from_s(content) end end |
#from_s(content) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rim/rim_info.rb', line 59 def from_s(content) attrs = {} # normalize line endings # this way riminfo files will be valid even if line endings are changed content = content.gsub("\r\n", "\n") checksum = content[0..39] # exclude \n after checksum content = content[41..-1] if content content.split("\n").each do |l| col = l.index(":") if col name, value = l[0..col-1], l[col+1..-1] if name && value attrs[name.strip.to_sym] = value.strip end end end end AttrsDef.each do |a| send("#{a}=".to_sym, attrs[a]) end @dirty = checksum != calc_sha1(content) end |
#to_dir(dir) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rim/rim_info.rb', line 95 def to_dir(dir) file = RimInfo.info_file(dir) content = "\n" content << "RIM Info file. You're welcome to read but don't write it.\n" content << "Instead, use RIM commands to do the things you want to do.\n" content << "BEWARE: Any manual modification will invalidate the file!\n" content << "\n" content << "#{to_s}\n" File.open(file, "wb") do |f| f.write(calc_sha1(content)+"\n") f.write(content) end end |