Class: Fixably::ActionPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/fixably/action_policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resourceObject (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

Raises:



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

Returns:

  • (Boolean)


12
13
14
# File 'lib/fixably/action_policy.rb', line 12

def create?
  resource.actions.include?(:create)
end

#delete!Object

Raises:



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/fixably/action_policy.rb', line 25

def delete?
  resource.actions.include?(:delete)
end

#list!Object

Raises:



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

Returns:

  • (Boolean)


38
39
40
# File 'lib/fixably/action_policy.rb', line 38

def list?
  resource.actions.include?(:list)
end

#show!Object

Raises:



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

Returns:

  • (Boolean)


51
52
53
# File 'lib/fixably/action_policy.rb', line 51

def show?
  resource.actions.include?(:show)
end

#update!Object

Raises:



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

Returns:

  • (Boolean)


64
65
66
# File 'lib/fixably/action_policy.rb', line 64

def update?
  resource.actions.include?(:update)
end