Class: Aegis::Action
- Inherits:
-
Object
- Object
- Aegis::Action
- Defined in:
- lib/aegis/action.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pluralize_resource ⇒ Object
readonly
Returns the value of attribute pluralize_resource.
-
#sieves ⇒ Object
readonly
Returns the value of attribute sieves.
-
#takes_object ⇒ Object
readonly
Returns the value of attribute takes_object.
-
#takes_parent_object ⇒ Object
readonly
Returns the value of attribute takes_parent_object.
-
#writing ⇒ Object
readonly
Returns the value of attribute writing.
Class Method Summary collapse
- .allow_to_all ⇒ Object
- .create(options = {}) ⇒ Object
- .deny_to_all ⇒ Object
- .destroy(options = {}) ⇒ Object
- .index(options = {}) ⇒ Object
- .show(options = {}) ⇒ Object
- .undefined ⇒ Object
- .update(options = {}) ⇒ Object
Instance Method Summary collapse
- #abstract? ⇒ Boolean
-
#initialize(name, options) ⇒ Action
constructor
A new instance of Action.
- #inspect ⇒ Object
- #may!(user, *args) ⇒ Object
- #may?(user, *args) ⇒ Boolean
- #update(options, use_defaults = false) ⇒ Object
- #update_attribute(options, key, use_defaults, default) ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Action
Returns a new instance of Action.
6 7 8 9 10 |
# File 'lib/aegis/action.rb', line 6 def initialize(name, ) @name = name.to_s @sieves = [] update(, true) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def name @name end |
#pluralize_resource ⇒ Object (readonly)
Returns the value of attribute pluralize_resource.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def pluralize_resource @pluralize_resource end |
#sieves ⇒ Object (readonly)
Returns the value of attribute sieves.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def sieves @sieves end |
#takes_object ⇒ Object (readonly)
Returns the value of attribute takes_object.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def takes_object @takes_object end |
#takes_parent_object ⇒ Object (readonly)
Returns the value of attribute takes_parent_object.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def takes_parent_object @takes_parent_object end |
#writing ⇒ Object (readonly)
Returns the value of attribute writing.
4 5 6 |
# File 'lib/aegis/action.rb', line 4 def writing @writing end |
Class Method Details
.allow_to_all ⇒ Object
60 61 62 63 64 |
# File 'lib/aegis/action.rb', line 60 def self.allow_to_all action = undefined action.sieves << Aegis::Sieve.allow_to_all action end |
.create(options = {}) ⇒ Object
48 49 50 |
# File 'lib/aegis/action.rb', line 48 def self.create( = {}) new('create', .reverse_merge(:takes_object => false, :writing => true)) end |
.deny_to_all ⇒ Object
66 67 68 69 70 |
# File 'lib/aegis/action.rb', line 66 def self.deny_to_all action = undefined action.sieves << Aegis::Sieve.deny_to_all action end |
.destroy(options = {}) ⇒ Object
52 53 54 |
# File 'lib/aegis/action.rb', line 52 def self.destroy( = {}) new('destroy', .reverse_merge(:takes_object => true, :writing => true)) end |
.index(options = {}) ⇒ Object
36 37 38 |
# File 'lib/aegis/action.rb', line 36 def self.index( = {}) new('index', .reverse_merge(:takes_object => false, :pluralize_resource => true, :writing => false)) end |
.show(options = {}) ⇒ Object
40 41 42 |
# File 'lib/aegis/action.rb', line 40 def self.show( = {}) new('show', .reverse_merge(:takes_object => true, :writing => false)) end |
.undefined ⇒ Object
56 57 58 |
# File 'lib/aegis/action.rb', line 56 def self.undefined new(nil, :takes_object => false, :writing => true) end |
.update(options = {}) ⇒ Object
44 45 46 |
# File 'lib/aegis/action.rb', line 44 def self.update( = {}) new('update', .reverse_merge(:takes_object => true, :writing => true)) end |
Instance Method Details
#abstract? ⇒ Boolean
72 73 74 |
# File 'lib/aegis/action.rb', line 72 def abstract? name.blank? end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/aegis/action.rb', line 76 def inspect "Action(#{{ :name => name, :takes_object => takes_object, :takes_parent_object => takes_parent_object, :sieves => sieves }.inspect})" end |
#may!(user, *args) ⇒ Object
32 33 34 |
# File 'lib/aegis/action.rb', line 32 def may!(user, *args) may?(user, *args) or raise Aegis::AccessDenied, "Access denied: #{args.inspect}" end |
#may?(user, *args) ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/aegis/action.rb', line 25 def may?(user, *args) context = extract_context(user, args) user.roles.any? do |role| may_as_role?(role, context, *args) end end |
#update(options, use_defaults = false) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/aegis/action.rb', line 12 def update(, use_defaults = false) update_attribute(, :takes_object, use_defaults, true) update_attribute(, :takes_parent_object, use_defaults, false) update_attribute(, :writing, use_defaults, true) update_attribute(, :pluralize_resource, use_defaults, false) end |
#update_attribute(options, key, use_defaults, default) ⇒ Object
19 20 21 22 23 |
# File 'lib/aegis/action.rb', line 19 def update_attribute(, key, use_defaults, default) value = [key] value = default if value.nil? && use_defaults instance_variable_set("@#{key}", value) unless value.nil? end |