Class: Twat::Migrate

Inherits:
Object
  • Object
show all
Defined in:
lib/twat/migration.rb

Instance Method Summary collapse

Instance Method Details

#migrate!(filename) ⇒ Object



3
4
5
6
# File 'lib/twat/migration.rb', line 3

def migrate!(filename)
  @file = filename
  migration_1
end

#migration_1Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/twat/migration.rb', line 8

def migration_1
  new = { accounts: {} }
  default = nil
  current = YAML.load_file(@file)
  current.each do |k, v|
    k = k.to_sym
    if k == :default
      default = v[:oauth_token]
    else
      new[:accounts][k] = v
    end
  end

  new[:accounts].each do |k, v|
    if v[:oauth_token] == default
      new[:default] = k
      break
    end
  end

  save(new)
end

#save(cf) ⇒ Object



31
32
33
34
35
36
# File 'lib/twat/migration.rb', line 31

def save(cf)
  File.open(@file, 'w') do |conf|
    conf.chmod(0600)
    conf.puts(cf.to_yaml)
  end
end