Sha256: 4624a15375e31964e2ef96554bcfa7dc05124b4918de819ebf7e97e240b7d754

Contents?: true

Size: 1.53 KB

Versions: 5

Compression:

Stored size: 1.53 KB

Contents

class Users < Entities

  def setup_data
    @default_type = :SQLiteAC
    @data_field_id = :id

    value_str :name
    value_str :full
    value_str :pass
    #value_array :accounts
    # The last account_index that got transmitted
    value_int :account_index
    # The last movement_index that got transmitted
    value_int :movement_index
  end

  def init
    user = Users.create('local', Digest::MD5.hexdigest((rand 2**128).to_s).to_s,
                        rand(2 ** 128).to_s)
    user.account_index, user.movement_index = 0, 0
    dputs(1) { "Created local user #{user}" }
    user
  end

  def load
    super
    if Users.search_by_name('local').count == 0
      dputs(0) { 'User init not here' }
      init
    end
  end

  def migration_1(u)
    u.account_index ||= -1
    u.movement_index ||= -1
  end

  def create(name, full = nil, pass = nil)
    if not full or not pass
      dputs(2) { "Creating with hash: #{name.inspect}" }
      name, full, pass = name[:name], name[:full], name[:pass]
    end
    new_user = super(:name => name, :full => full, :pass => pass)
    new_user.account_index, new_user.movement_index = -1, -1
    new_user
  end
end

class User < Entity
  def update_movement_index
    self.movement_index = Users.match_by_name('local').movement_index - 1
  end

  def update_account_index
    self.account_index = Users.match_by_name('local').account_index - 1
  end

  def update_all
    update_movement_index
    update_account_index
  end

  def reset_id
    self.full = Digest::MD5.hexdigest((rand 2**128).to_s).to_s
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
africompta-1.9.1312 lib/africompta/entities/users.rb
africompta-1.9.13.pre.12 lib/africompta/entities/users.rb
africompta-1.9.13.pre.11 lib/africompta/entities/users.rb
africompta-1.9.13.pre.10 lib/africompta/entities/users.rb
africompta-1.9.11 lib/africompta/entities/users.rb