mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
add comment
This commit is contained in:
parent
0708c3d4c0
commit
59c91bfb8f
1 changed files with 11 additions and 1 deletions
12
lib/Item.rb
12
lib/Item.rb
|
@ -22,10 +22,14 @@ module MPW
|
||||||
attr_accessor :last_edit
|
attr_accessor :last_edit
|
||||||
attr_accessor :created
|
attr_accessor :created
|
||||||
|
|
||||||
|
# Constructor
|
||||||
|
# Create a new item
|
||||||
|
# @args: options -> a hash of parameter
|
||||||
|
# raise an error if the hash hasn't the key name
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
if not options.has_key?(:name) or options[:name].to_s.empty?
|
if not options.has_key?(:name) or options[:name].to_s.empty?
|
||||||
@error_msg = I18n.t('error.update.name_empty')
|
@error_msg = I18n.t('error.update.name_empty')
|
||||||
raise ExceptionMPW @error_msg
|
raise @error_msg
|
||||||
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?
|
||||||
|
@ -39,6 +43,9 @@ module MPW
|
||||||
update(options)
|
update(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Update the item
|
||||||
|
# @args: options -> a hash of parameter
|
||||||
|
# @rtrn: true if the item is update
|
||||||
def update(options={})
|
def update(options={})
|
||||||
if options.has_key?(:name) and options[:name].to_s.empty?
|
if options.has_key?(:name) and options[:name].to_s.empty?
|
||||||
@error_msg = I18n.t('error.update.name_empty')
|
@error_msg = I18n.t('error.update.name_empty')
|
||||||
|
@ -58,6 +65,8 @@ module MPW
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Delete all data
|
||||||
|
# @rtrn: true
|
||||||
def delete
|
def delete
|
||||||
@id = nil
|
@id = nil
|
||||||
@name = nil
|
@name = nil
|
||||||
|
@ -82,6 +91,7 @@ module MPW
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generate an random id
|
||||||
private
|
private
|
||||||
def generate_id
|
def generate_id
|
||||||
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
|
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
|
||||||
|
|
Loading…
Add table
Reference in a new issue