Class: ActionAction::Base
- Inherits:
-
Object
- Object
- ActionAction::Base
show all
- Extended by:
- Callbacks
- Includes:
- Statuses, ActiveSupport::Callbacks
- Defined in:
- lib/action_action/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Callbacks
after_perform, around_perform, before_perform
Constructor Details
#initialize(params = {}) ⇒ Base
Returns a new instance of Base.
11
12
13
14
15
16
|
# File 'lib/action_action/base.rb', line 11
def initialize(params = {})
@params = params
@params.map do |parameter, value|
instance_variable_set(:"@#{parameter}", value)
end
end
|
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
9
10
11
|
# File 'lib/action_action/base.rb', line 9
def message
@message
end
|
#params ⇒ Object
Returns the value of attribute params.
9
10
11
|
# File 'lib/action_action/base.rb', line 9
def params
@params
end
|
#result ⇒ Object
Returns the value of attribute result.
9
10
11
|
# File 'lib/action_action/base.rb', line 9
def result
@result
end
|
#status ⇒ Object
Returns the value of attribute status.
9
10
11
|
# File 'lib/action_action/base.rb', line 9
def status
@status
end
|
Class Method Details
33
34
35
|
# File 'lib/action_action/base.rb', line 33
def perform(*args)
new.perform_with_callbacks(*args)
end
|
37
38
39
40
41
42
|
# File 'lib/action_action/base.rb', line 37
def perform!(*args)
if (context = perform(*args)).success?
return context
end
raise ActionAction::Error.new(context.message)
end
|
.require(params = {}) ⇒ Object
Also known as:
set!, with!, require!
21
22
23
|
# File 'lib/action_action/base.rb', line 21
def require(params = {})
Parameters.new(self).require(params)
end
|
.set(params = {}) ⇒ Object
Also known as:
with
28
29
30
|
# File 'lib/action_action/base.rb', line 28
def set(params = {})
Parameters.new(self, params).set(params)
end
|
Instance Method Details
45
46
47
|
# File 'lib/action_action/base.rb', line 45
def perform(*args)
perform_with_callbacks(*args)
end
|
55
56
57
58
59
60
|
# File 'lib/action_action/base.rb', line 55
def perform_with_callbacks(*args)
run_callbacks :perform do
perform_without_callbacks(*args)
end
self
end
|
49
50
51
52
53
|
# File 'lib/action_action/base.rb', line 49
def perform_without_callbacks(*args)
@result = perform(*args)
success! if @status.nil?
@result
end
|