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)


106
107
108
# File 'lib/mgit/appdata.rb', line 106

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

#load(key, default) ⇒ Object



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

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

#migrate!Object



110
111
112
113
114
115
# File 'lib/mgit/appdata.rb', line 110

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



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

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
    fail ImplementationError, "AppDataVersion1::save! called with unknown key #{key}."
  end
end

#setup!Object



117
118
119
120
121
# File 'lib/mgit/appdata.rb', line 117

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



102
103
104
# File 'lib/mgit/appdata.rb', line 102

def version
  1
end