class GoogleDrive::AclEntry
An entry of an ACL (access control list) of a spreadsheet.
Use GoogleDrive::Acl#[] to get GoogleDrive::AclEntry
object.
This code is based on github.com/guyboertje/gdata-spreadsheet-ruby .
Attributes
@api private
@api private
Public Class Methods
params_or_api_permission
is a Hash object with keys :type
, :email_address
, :domain
, :role
and :allow_file_discovery
. See GoogleDrive::Acl#push
for description of the parameters.
# File lib/google_drive/acl_entry.rb, line 19 def initialize(params_or_api_permission, acl = nil) @acl = acl if acl @api_permission = params_or_api_permission @params = nil delegate_api_methods(self, @api_permission) else @api_permission = nil @params = convert_params(params_or_api_permission) end end
Public Instance Methods
# File lib/google_drive/acl_entry.rb, line 59 def additional_roles @params ? @params[:additionalRoles] : @api_permission.additional_roles end
If false
, the file is shared only with people who know the link. Only used for type “anyone”.
# File lib/google_drive/acl_entry.rb, line 99 def allow_file_discovery @params ? @params[:allow_file_discovery] : @api_permission.allow_file_discovery end
The Google Apps domain name.
# File lib/google_drive/acl_entry.rb, line 73 def domain @params ? @params[:domain] : @api_permission.domain end
Email address of the user or the group.
# File lib/google_drive/acl_entry.rb, line 68 def email_address @params ? @params[:email_address] : @api_permission.email_address end
# File lib/google_drive/acl_entry.rb, line 63 def id @params ? @params[:id] : @api_permission.id end
# File lib/google_drive/acl_entry.rb, line 125 def inspect case type when 'user', 'group' format( "\#<%p type=%p, email_address=%p, role=%p>", self.class, type, email_address, role ) when 'domain' format( "\#<%p type=%p, domain=%p, role=%p>", self.class, type, domain, role ) when 'anyone' format( "\#<%p type=%p, role=%p, allow_file_discovery=%p>", self.class, type, role, allow_file_discovery ) else format("\#<%p type=%p, role=%p>", self.class, type, role) end end
The role given to the scope. One of:
-
“owner”: The owner.
-
“writer”: With read/write access.
-
“reader”: With read-only access.
# File lib/google_drive/acl_entry.rb, line 43 def role @params ? @params[:role] : @api_permission.role end
Changes the role of the scope.
e.g.
spreadsheet.acl[1].role = "writer"
# File lib/google_drive/acl_entry.rb, line 116 def role=(role) if @params @params[:role] = role else @api_permission.role = role @acl.update_role(self) end end
Type of the scope. One of:
-
“user”: a Google account specified by the
email_address
field. -
“group”: a Google Group specified by the
email_address
field. -
“domain”: a Google Apps domain specified by the domain field.
-
“anyone”: Publicly shared with all users.
# File lib/google_drive/acl_entry.rb, line 53 def type @params ? @params[:type] : @api_permission.type end
# File lib/google_drive/acl_entry.rb, line 77 def value if @params case @params[:type] when 'user', 'group' @params[:email_address] when 'domain' @params[:domain] end else case @api_permission.type when 'user', 'group' @api_permission.email_address when 'domain' @api_permission.domain end end end
If true
, the file is shared only with people who know the link. Only used for type “anyone”.
# File lib/google_drive/acl_entry.rb, line 106 def with_link allow_file_discovery == false end
Private Instance Methods
Normalizes the key to Symbol, and converts parameters in the old version.
# File lib/google_drive/acl_entry.rb, line 150 def convert_params(orig_params) new_params = {} value = nil orig_params.each do |k, v| k = k.to_s case k when 'scope_type' new_params[:type] = (v == 'default' ? 'anyone' : v) when 'scope' new_params[:value] = v when 'with_key', 'withLink' new_params[:allow_file_discovery] = !v when 'value' value = v else new_params[k.intern] = v end end if value case new_params[:type] when 'user', 'group' new_params[:email_address] = value when 'domain' new_params[:domain] = value end end new_params end