Class: SteelWheel::Handler
Overview
Base class that defines main flow
Constant Summary
Constants included
from Callbacks
Callbacks::NOOP
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
included
Methods included from Callbacks
#callbacks, #failure, #success
Methods included from Shortcuts
#depends_on, #finder, included, #verify
Methods included from Components
included
Methods included from Filters
included
Constructor Details
#initialize(params = {}) ⇒ Handler
30
31
32
33
|
# File 'lib/steel_wheel/handler.rb', line 30
def initialize(params = {})
@http_status = :ok
prepare_params(params)
end
|
Instance Attribute Details
Returns the value of attribute form_input.
19
20
21
|
# File 'lib/steel_wheel/handler.rb', line 19
def form_input
@form_input
end
|
#helpers ⇒ Object
Returns the value of attribute helpers.
20
21
22
|
# File 'lib/steel_wheel/handler.rb', line 20
def helpers
@helpers
end
|
#http_status ⇒ Object
Returns the value of attribute http_status.
20
21
22
|
# File 'lib/steel_wheel/handler.rb', line 20
def http_status
@http_status
end
|
Returns the value of attribute input.
19
20
21
|
# File 'lib/steel_wheel/handler.rb', line 19
def input
@input
end
|
Class Method Details
.generic_validation_keys(*keys) ⇒ Object
.handle(input = {}, &block) ⇒ Object
36
37
38
|
# File 'lib/steel_wheel/handler.rb', line 36
def handle(input = {}, &block)
new(input).handle(&block)
end
|
.inherited(subclass) ⇒ Object
44
45
46
47
48
|
# File 'lib/steel_wheel/handler.rb', line 44
def inherited(subclass)
super
subclass.url_params(url_params_definition)
subclass.form(form_definition)
end
|
.name ⇒ Object
40
41
42
|
# File 'lib/steel_wheel/handler.rb', line 40
def name
to_s.match?(/Class/) ? 'SteelWheel::Handler' : to_s
end
|
Instance Method Details
#current_action ⇒ Object
80
81
82
|
# File 'lib/steel_wheel/handler.rb', line 80
def current_action
ActiveSupport::StringInquirer.new(url_params.action)
end
|
#handle {|_self| ... } ⇒ Object
55
56
57
58
59
60
61
62
63
|
# File 'lib/steel_wheel/handler.rb', line 55
def handle(&block)
yield(self) if block
validate_preconditions
return self unless success?
on_validation_success
errors.empty? ? success_callback : failure_self
self
end
|
#on_validation_success ⇒ Object
65
66
67
|
# File 'lib/steel_wheel/handler.rb', line 65
def on_validation_success
end
|
#status ⇒ Object
73
74
75
76
77
78
|
# File 'lib/steel_wheel/handler.rb', line 73
def status
return :ok if errors.empty?
return errors.keys.first unless defined?(ActiveModel::Error)
errors.map(&:type).first
end
|
#success? ⇒ Boolean
69
70
71
|
# File 'lib/steel_wheel/handler.rb', line 69
def success?
http_status == :ok
end
|