1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-19 12:59:30 +00:00

re add id for item

This commit is contained in:
Adrien Waksberg 2016-10-16 09:41:13 +02:00
parent dc8a8d76fc
commit fbac3df193
2 changed files with 19 additions and 6 deletions

View file

@ -21,6 +21,7 @@ require 'i18n'
module MPW
class Item
attr_accessor :id
attr_accessor :group
attr_accessor :host
attr_accessor :protocol
@ -41,8 +42,10 @@ class Item
end
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
@id = generate_id
@created = Time.now.to_i
else
@id = options[:id]
@created = options[:created]
@last_edit = options[:last_edit]
options[:no_update_last_edit] = true
@ -74,6 +77,7 @@ class Item
# Delete all data
def delete
@id = nil
@group = nil
@host = nil
@protocol = nil
@ -86,11 +90,17 @@ class Item
end
def empty?
return @host.to_s.empty?
return @id.to_s.empty?
end
def nil?
return false
end
# Generate an random id
private
def generate_id
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
end
end
end

View file

@ -82,7 +82,8 @@ class MPW
if not data.nil? and not data.empty?
YAML.load(data).each_value do |d|
@data.push(Item.new(group: d['group'],
@data.push(Item.new(id: d['id'],
group: d['group'],
host: d['host'],
protocol: d['protocol'],
user: d['user'],
@ -108,7 +109,8 @@ class MPW
@data.each do |item|
next if item.empty?
data.merge!("#{item.user}@#{item.host}" => {'group' => item.group,
data.merge!("#{item.user}@#{item.host}" => {'id' => item.id,
'group' => item.group,
'host' => item.host,
'protocol' => item.protocol,
'user' => item.user,
@ -389,7 +391,8 @@ class MPW
remote.list.each do |r|
next if r.last_edit <= get_last_sync
item = Item.new(group: r.group,
item = Item.new(id: r.id,
group: r.group,
host: r.host,
protocol: r.protocol,
user: r.user,