Class: Uncouple::Action

Inherits:
Object
  • Object
show all
Includes:
Authorization
Defined in:
lib/uncouple/action.rb,
lib/uncouple/action/authorization.rb,
lib/uncouple/action/instrumentation.rb

Defined Under Namespace

Modules: Authorization, Instrumentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#authorize!, #current_user, #perform_with_authorization

Constructor Details

#initialize(params = nil) ⇒ Action

Returns a new instance of Action.



10
11
12
# File 'lib/uncouple/action.rb', line 10

def initialize(params=nil)
  @params = recast_parameters(params || {})
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



8
9
10
# File 'lib/uncouple/action.rb', line 8

def params
  @params
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/uncouple/action.rb', line 22

def failure?
  !success?
end

#performObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/uncouple/action.rb', line 14

def perform
  raise NotImplementedError, "Overwrite `perform` in your action. Params: #{params}"
end

#perform?(&block) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/uncouple/action.rb', line 26

def perform?(&block)
  perform
  block.call(self) if block_given?
  success?
end

#success?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/uncouple/action.rb', line 18

def success?
  @success
end