Class: Readymade::Action
- Inherits:
-
Object
show all
- Defined in:
- lib/readymade/action.rb
Defined Under Namespace
Classes: NonKeywordArgumentsError, UnSuccessError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args = {}) ⇒ Action
Returns a new instance of Action.
34
35
36
37
38
39
40
41
|
# File 'lib/readymade/action.rb', line 34
def initialize(args = {})
raise NonKeywordArgumentsError if args.present? && !args.is_a?(Hash)
@args = @data = args
@args.each do |name, value|
instance_variable_set("@#{name}", value)
end
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
32
33
34
|
# File 'lib/readymade/action.rb', line 32
def args
@args
end
|
#data ⇒ Object
Returns the value of attribute data.
32
33
34
|
# File 'lib/readymade/action.rb', line 32
def data
@data
end
|
Class Method Details
.call(*args, &block) ⇒ Object
12
13
14
|
# File 'lib/readymade/action.rb', line 12
def self.call(*args, &block)
new(*args, &block).call
end
|
.call!(*args, &block) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/readymade/action.rb', line 16
def self.call!(*args, &block)
new(*args, &block).call!.then do |res|
return res if res.try(:success?) || res.try(:consider_success?)
raise UnSuccessError.new(res.humanized_errors)
end
end
|
.call_async(*args, &block) ⇒ Object
24
25
26
|
# File 'lib/readymade/action.rb', line 24
def self.call_async(*args, &block)
new(*args, &block).call_async
end
|
.call_async!(*args, &block) ⇒ Object
28
29
30
|
# File 'lib/readymade/action.rb', line 28
def self.call_async!(*args, &block)
new(*args, &block).call_async!
end
|
Instance Method Details
#call ⇒ Object
43
|
# File 'lib/readymade/action.rb', line 43
def call; end
|
#call! ⇒ Object
45
46
47
|
# File 'lib/readymade/action.rb', line 45
def call!
call
end
|
#call_async ⇒ Object
49
50
51
|
# File 'lib/readymade/action.rb', line 49
def call_async
::Readymade::BackgroundJob.perform_later(class_name: self.class.name, **args)
end
|
#call_async! ⇒ Object
53
54
55
|
# File 'lib/readymade/action.rb', line 53
def call_async!
::Readymade::BackgroundBangJob.perform_later(class_name: self.class.name, **args)
end
|
#response(status, *args) ⇒ Object
57
58
59
|
# File 'lib/readymade/action.rb', line 57
def response(status, *args)
Response.new(status, *args)
end
|