Class: Parse::ACL::Permission
- Inherits:
- Object
- Object
- Parse::ACL::Permission
- Includes:
- ActiveModel::Model, ActiveModel::Serializers::JSON
- Defined in:
- lib/parse/model/acl.rb
Overview
The Permission class tracks the read and write permissions for a specific ACL entry. The value of an Parse-ACL hash only contains two keys: “read” and “write”.
# Example of the ACL format
{ "*": { "read": true },
"3KmCvT7Zsb": { "read": true, "write": true },
"role:Admins": { "write": true }
}
This would be managed as:
{ "*": ACL::Permission.new(true),
"3KmCvT7Zsb": ACL::Permission.new(true, true)
"role:Amdins": ACL::Permission.new(false,true)
}
Instance Attribute Summary collapse
- #read ⇒ Boolean readonly
The read permission state.
- #write ⇒ Boolean readonly
The write permission state.
Instance Method Summary collapse
- #==(per) ⇒ Boolean
Whether two permission instances have the same permissions.
- #as_json(*args) ⇒ Hash
A Parse-compatible ACL-hash.
- #attributes ⇒ Hash
- #initialize(r_perm = nil, w_perm = nil) ⇒ Permission constructor
Create a new permission with the given read and write privileges.
- #no_read! ⇒ void
Sets the read value of the permission to false.
- #no_write! ⇒ void
Sets the write value of the permission to false.
- #present? ⇒ Boolean
Whether there is at least one permission set to true.
- #read!(value = true) ⇒ void
Sets the read value of the permission.
- #write!(value = true) ⇒ void
Sets the write value of the permission.
Constructor Details
#new(read = nil, write = nil) ⇒ Permission #new(hash) ⇒ Permission
Create a new permission with the given read and write privileges.
463 464 465 466 467 468 469 470 471 472 | # File 'lib/parse/model/acl.rb', line 463 def initialize(r_perm = nil, w_perm = nil) if r_perm.is_a?(Hash) r_perm = r_perm.symbolize_keys @read = r_perm[:read].present? @write = r_perm[:write].present? else @read = r_perm.present? @write = w_perm.present? end end |
Instance Attribute Details
#read ⇒ Boolean (readonly)
The read permission state.
446 447 448 | # File 'lib/parse/model/acl.rb', line 446 def read @read end |
#write ⇒ Boolean (readonly)
The write permission state.
450 451 452 | # File 'lib/parse/model/acl.rb', line 450 def write @write end |
Instance Method Details
#==(per) ⇒ Boolean
Returns whether two permission instances have the same permissions.
475 476 477 478 | # File 'lib/parse/model/acl.rb', line 475 def ==(per) return false unless per.is_a?(self.class) @read == per.read && @write == per.write end |
#as_json(*args) ⇒ Hash
Returns A Parse-compatible ACL-hash. Omission or false on a priviledge means don't include it.
482 483 484 485 486 487 | # File 'lib/parse/model/acl.rb', line 482 def as_json(*args) h = {} h[:read] = true if @read h[:write] = true if @write h.empty? ? nil : h.as_json end |
#attributes ⇒ Hash
490 491 492 493 494 495 | # File 'lib/parse/model/acl.rb', line 490 def attributes h = {} h.merge!(read: :boolean) if @read h.merge!(write: :boolean) if @write h end |
#no_read! ⇒ void
This method returns an undefined value.
Sets the read value of the permission to false.
526 527 528 | # File 'lib/parse/model/acl.rb', line 526 def no_read! @write = false end |
#no_write! ⇒ void
This method returns an undefined value.
Sets the write value of the permission to false.
533 534 535 | # File 'lib/parse/model/acl.rb', line 533 def no_write! @write = false end |
#present? ⇒ Boolean
Returns whether there is at least one permission set to true.
503 504 505 | # File 'lib/parse/model/acl.rb', line 503 def present? @read.present? || @write.present? end |
#read!(value = true) ⇒ void
Setting the value in this manner is not dirty tracked.
This method returns an undefined value.
Sets the read value of the permission. Defaults to true.
511 512 513 | # File 'lib/parse/model/acl.rb', line 511 def read!(value = true) @read = value end |
#write!(value = true) ⇒ void
Setting the value in this manner is not dirty tracked.
This method returns an undefined value.
Sets the write value of the permission. Defaults to true.
519 520 521 | # File 'lib/parse/model/acl.rb', line 519 def write!(value = true) @write = value end |