Class: Remotes

Inherits:
Entities
  • Object
show all
Defined in:
lib/africompta/entities/remote.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_db(url, name, pass) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/africompta/entities/remote.rb', line 18

def self.get_db(url, name, pass)
  vers = Net::HTTP.get(URI.parse("#{url}/merge/version/#{name},#{pass}"))
  if vers != $VERSION.to_s
    return (vers =~ /not known/) ? 'User and/or password wrong' : 'Version mismatch'
  end

  db = Net::HTTP.get(URI.parse("#{url}/merge/get_db/#{name},#{pass}"))

  SQLite.dbs_close_all
  # All accounting-stuff is stored in the same database
  IO.write(Accounts.storage[:SQLiteAC].db_file, db)
  IO.write('/tmp/compta.db', db)
  SQLite.dbs_open_load_migrate

  # Delete all users except for the 'local' who needs a new id
  Users.search_all_.each { |u|
    if u.name == 'local'
      u.reset_id
    else
      u.delete
    end
  }

  # Delete all other remotes and add ourselves
  Remotes.search_all_.each { |r| r.delete }
  remote = Remotes.create(url: url, name: name, pass: pass)

  # Update all indexes
  ret = remote.do_copied
  if ret == true
    remote
  else
    ret
  end
end

Instance Method Details

#create(d) ⇒ Object



3
4
5
6
7
8
# File 'lib/africompta/entities/remote.rb', line 3

def create(d)
  r = super(d)
  d.has_key?(:account_index) || r. = 0
  d.has_key?(:movement_index) || r.movement_index = 0
  r
end

#setup_dataObject



10
11
12
13
14
15
16
# File 'lib/africompta/entities/remote.rb', line 10

def setup_data
  value_str :url
  value_str :name
  value_str :pass
  value_int :account_index
  value_int :movement_index
end