Class: RIM::RimInfo

Inherits:
Object
  • Object
show all
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_sha1:   8347982374198379842984562095637243593092
target_revision: 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,
  :subdir
]
@@git_infos =
{
  :committer_date => "%ci"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#infosObject

Returns the value of attribute infos.



43
44
45
# File 'lib/rim/rim_info.rb', line 43

def infos
  @infos
end

Class Method Details

.exists?(dir) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/rim/rim_info.rb', line 45

def self.exists?(dir)
  File.exist?(info_file(dir))
end

.from_dir(dir) ⇒ Object



49
50
51
52
53
# File 'lib/rim/rim_info.rb', line 49

def self.from_dir(dir)
  mi = self.new
  mi.from_dir(dir)
  mi
end

.from_s(content) ⇒ Object



55
56
57
58
59
# File 'lib/rim/rim_info.rb', line 55

def self.from_s(content)
  mi = self.new
  mi.from_s(content)
  mi
end

.git_infosObject



61
62
63
# File 'lib/rim/rim_info.rb', line 61

def self.git_infos
  @@git_infos
end

Instance Method Details

#dirty?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/rim/rim_info.rb', line 65

def dirty?
  @dirty
end

#from_dir(dir) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/rim/rim_info.rb', line 103

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rim/rim_info.rb', line 69

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
    if attrs[:subdir] == ""
      attrs[:subdir] = nil
    end
  end
  AttrsDef.each do |a|
    send("#{a}=".to_sym, attrs[a])
  end
  @@git_infos.each_pair do |key, value|
    if attrs.has_key?(key)
      @infos ||= {}
      @infos[key] = attrs[key]
    end
  end
  @dirty = checksum != calc_sha1(content)
end

#to_dir(dir) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rim/rim_info.rb', line 114

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

#to_sObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/rim/rim_info.rb', line 128

def to_s
  i = @infos || {}
  max_len = (AttrsDef + i.keys).collect{|a| a.size}.max
  s = AttrsDef.collect { |a|
    "#{a.to_s.ljust(max_len)}: #{send(a)}"
  }.join("\n")
  if !i.empty?
    s << "\n\n"
    i.each_pair { |key, value| 
      s << "#{key.to_s.ljust(max_len)}: #{value.to_s}\n"
    }
  end
  s
end