Class: Fixably::ActionPolicy
- Inherits:
-
Object
- Object
- Fixably::ActionPolicy
- Defined in:
- lib/fixably/action_policy.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #create! ⇒ Object
- #create? ⇒ Boolean
- #delete! ⇒ Object
- #delete? ⇒ Boolean
-
#initialize(resource:) ⇒ ActionPolicy
constructor
A new instance of ActionPolicy.
- #list! ⇒ Object
- #list? ⇒ Boolean
- #show! ⇒ Object
- #show? ⇒ Boolean
- #update! ⇒ Object
- #update? ⇒ Boolean
Constructor Details
#initialize(resource:) ⇒ ActionPolicy
Returns a new instance of ActionPolicy.
7 8 9 10 |
# File 'lib/fixably/action_policy.rb', line 7 def initialize(resource:) @resource = resource.instance_of?(Class) ? resource : resource.class validate_resource! end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/fixably/action_policy.rb', line 5 def resource @resource end |
Instance Method Details
#create! ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fixably/action_policy.rb', line 16 def create! return true if create? raise( UnsupportedError, "Fixably does not support creating #{resource_name}" ) end |
#create? ⇒ Boolean
12 13 14 |
# File 'lib/fixably/action_policy.rb', line 12 def create? resource.actions.include?(:create) end |
#delete! ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/fixably/action_policy.rb', line 29 def delete! return true if delete? raise( UnsupportedError, "Fixably does not support deleting #{resource_name}" ) end |
#delete? ⇒ Boolean
25 26 27 |
# File 'lib/fixably/action_policy.rb', line 25 def delete? resource.actions.include?(:delete) end |
#list! ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/fixably/action_policy.rb', line 42 def list! return true if list? raise( UnsupportedError, "Fixably does not support listing #{resource_name}" ) end |
#list? ⇒ Boolean
38 39 40 |
# File 'lib/fixably/action_policy.rb', line 38 def list? resource.actions.include?(:list) end |
#show! ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/fixably/action_policy.rb', line 55 def show! return true if show? raise( UnsupportedError, "Fixably does not support retrieving #{resource_name}" ) end |
#show? ⇒ Boolean
51 52 53 |
# File 'lib/fixably/action_policy.rb', line 51 def show? resource.actions.include?(:show) end |
#update! ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/fixably/action_policy.rb', line 68 def update! return true if update? raise( UnsupportedError, "Fixably does not support updating #{resource_name}" ) end |
#update? ⇒ Boolean
64 65 66 |
# File 'lib/fixably/action_policy.rb', line 64 def update? resource.actions.include?(:update) end |