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:
parent
dc8a8d76fc
commit
fbac3df193
2 changed files with 19 additions and 6 deletions
|
@ -21,6 +21,7 @@ require 'i18n'
|
||||||
module MPW
|
module MPW
|
||||||
class Item
|
class Item
|
||||||
|
|
||||||
|
attr_accessor :id
|
||||||
attr_accessor :group
|
attr_accessor :group
|
||||||
attr_accessor :host
|
attr_accessor :host
|
||||||
attr_accessor :protocol
|
attr_accessor :protocol
|
||||||
|
@ -40,9 +41,11 @@ class Item
|
||||||
raise I18n.t('error.update.name_empty')
|
raise I18n.t('error.update.name_empty')
|
||||||
end
|
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?
|
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
|
@created = Time.now.to_i
|
||||||
else
|
else
|
||||||
|
@id = options[:id]
|
||||||
@created = options[:created]
|
@created = options[:created]
|
||||||
@last_edit = options[:last_edit]
|
@last_edit = options[:last_edit]
|
||||||
options[:no_update_last_edit] = true
|
options[:no_update_last_edit] = true
|
||||||
|
@ -74,6 +77,7 @@ class Item
|
||||||
|
|
||||||
# Delete all data
|
# Delete all data
|
||||||
def delete
|
def delete
|
||||||
|
@id = nil
|
||||||
@group = nil
|
@group = nil
|
||||||
@host = nil
|
@host = nil
|
||||||
@protocol = nil
|
@protocol = nil
|
||||||
|
@ -86,11 +90,17 @@ class Item
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty?
|
def empty?
|
||||||
return @host.to_s.empty?
|
return @id.to_s.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def nil?
|
def nil?
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate an random id
|
||||||
|
private
|
||||||
|
def generate_id
|
||||||
|
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ class MPW
|
||||||
|
|
||||||
if not data.nil? and not data.empty?
|
if not data.nil? and not data.empty?
|
||||||
YAML.load(data).each_value do |d|
|
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'],
|
host: d['host'],
|
||||||
protocol: d['protocol'],
|
protocol: d['protocol'],
|
||||||
user: d['user'],
|
user: d['user'],
|
||||||
|
@ -108,7 +109,8 @@ class MPW
|
||||||
@data.each do |item|
|
@data.each do |item|
|
||||||
next if item.empty?
|
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,
|
'host' => item.host,
|
||||||
'protocol' => item.protocol,
|
'protocol' => item.protocol,
|
||||||
'user' => item.user,
|
'user' => item.user,
|
||||||
|
@ -389,7 +391,8 @@ class MPW
|
||||||
remote.list.each do |r|
|
remote.list.each do |r|
|
||||||
next if r.last_edit <= get_last_sync
|
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,
|
host: r.host,
|
||||||
protocol: r.protocol,
|
protocol: r.protocol,
|
||||||
user: r.user,
|
user: r.user,
|
||||||
|
|
Loading…
Add table
Reference in a new issue