Class: Lastpass::Group
- Inherits:
-
Object
- Object
- Lastpass::Group
- Defined in:
- lib/lastpass-api/group.rb
Overview
Interact with a Lastpass group/folder
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the group.
-
#initialize(params) ⇒ Group
constructor
A new instance of Group.
-
#inspect ⇒ Object
private
Hide instance variables and values.
-
#save ⇒ Object
Either create or update a group, depending on what was changed on the group object before this method was called.
-
#to_hash ⇒ Hash
(also: #to_h)
Hash representation of the account object.
-
#update(params) ⇒ Object
Update the group details.
Constructor Details
#initialize(params) ⇒ Group
Returns a new instance of Group.
9 10 11 12 |
# File 'lib/lastpass-api/group.rb', line 9 def initialize( params ) params[:name].chomp!( '/' ) if params[:name]&.end_with? '/' params_to_group( params ) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/lastpass-api/group.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/lastpass-api/group.rb', line 6 def name @name end |
Instance Method Details
#delete ⇒ Object
Delete the group
52 53 54 55 |
# File 'lib/lastpass-api/group.rb', line 52 def delete Cli.rm( @id ) @deleted = true end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hide instance variables and values
75 76 77 78 |
# File 'lib/lastpass-api/group.rb', line 75 def inspect original_inspect = super original_inspect.split( ' ' ).first << '>' end |
#save ⇒ Object
Either create or update a group, depending on what was changed on the group object before this method was called.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lastpass-api/group.rb', line 35 def save deleted! if @deleted # If there is an ID, update that entry if @id Cli.edit_group( @id, name: @name ) else # If no ID, that means this is a new entry Cli.add_group( @name ) set_id_after_save end self end |
#to_hash ⇒ Hash Also known as: to_h
Hash representation of the account object
63 64 65 66 67 68 |
# File 'lib/lastpass-api/group.rb', line 63 def to_hash params = {} params[:id] = @id if @id params[:name] = @name if @name params end |
#update(params) ⇒ Object
Update the group details
20 21 22 23 24 25 |
# File 'lib/lastpass-api/group.rb', line 20 def update( params ) deleted! if @deleted params.delete( :id ) # Prevent overwriting ID params_to_group( params ) save end |