Class: MGit::AppData::AppDataVersion1

Inherits:
AppDataVersion show all
Defined in:
lib/mgit/appdata.rb

Instance Method Summary collapse

Methods inherited from AppDataVersion

#<=>, active, inherited, latest, sorted, updates

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/mgit/appdata.rb', line 108

def active?
  File.directory?(config_dir) && (load(:version, nil) == '1')
end

#load(key, default) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/mgit/appdata.rb', line 125

def load(key, default)
  case key
  when :repositories
    repos = YAML.load_file(repo_file)
    repos ? repos : default
  when *Configuration::KEYS.keys, :version
    config = YAML.load_file(config_file)
    (config && config.has_key?(key)) ? config[key] : default
  else
    raise ImplementationError.new("AppDataVersion1::load called with unknown key #{key}.")
  end
end

#migrate!Object



112
113
114
115
116
117
# File 'lib/mgit/appdata.rb', line 112

def migrate!
  setup!

  old_repofile = LegacyAppData.new.send(:repofile)
  FileUtils.mv(old_repofile, repo_file) if File.file?(old_repofile)
end

#save!(key, value) ⇒ Object



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/mgit/appdata.rb', line 138

def save!(key, value)
  case key
  when :repositories
    File.open(repo_file, 'w') { |fd| fd.write value.to_yaml }
  when *Configuration::KEYS.keys
    config = YAML.load_file(config_file)
    config[key] = value
    File.open(config_file, 'w') { |fd| fd.write config.to_yaml }
  else
    raise ImplementationError.new("AppDataVersion1::save! called with unknown key #{key}.")
  end
end

#setup!Object



119
120
121
122
123
# File 'lib/mgit/appdata.rb', line 119

def setup!
  FileUtils.mkdir_p(config_dir)
  File.open(config_file, 'w') { |fd| fd.write ({ :version => '1' }.to_yaml) }
  FileUtils.touch(repo_file)
end

#versionObject



104
105
106
# File 'lib/mgit/appdata.rb', line 104

def version
  1
end