Class: Permissions
- Inherits:
-
Object
- Object
- Permissions
- Defined in:
- lib/permissions.rb
Defined Under Namespace
Modules: Authorizable
Constant Summary collapse
- VERSION =
'0.1.3'
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
- #authorize?(key, *args) ⇒ Boolean
- #deep_dup(initial_permissions = {}) ⇒ Object
- #for(*keys, &block) ⇒ Object
-
#initialize(permissions = {}) ⇒ Permissions
constructor
A new instance of Permissions.
Constructor Details
#initialize(permissions = {}) ⇒ Permissions
Returns a new instance of Permissions.
16 17 18 19 20 21 22 23 24 |
# File 'lib/permissions.rb', line 16 def initialize( = {}) @permissions = if block_given? @default = Proc.new else @default = proc { false } end end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
14 15 16 |
# File 'lib/permissions.rb', line 14 def default @default end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
14 15 16 |
# File 'lib/permissions.rb', line 14 def @permissions end |
Instance Method Details
#authorize?(key, *args) ⇒ Boolean
30 31 32 |
# File 'lib/permissions.rb', line 30 def (key, *args) .fetch(key, default).call(*args) end |
#deep_dup(initial_permissions = {}) ⇒ Object
34 35 36 |
# File 'lib/permissions.rb', line 34 def deep_dup( = {}) self.class.new(.merge()) { default } end |
#for(*keys, &block) ⇒ Object
26 27 28 |
# File 'lib/permissions.rb', line 26 def for(*keys, &block) keys.each { |key| [key] = block } end |