Class: Subroutine::Op
- Inherits:
-
Object
- Object
- Subroutine::Op
- Includes:
- ActiveModel::Model, ActiveModel::Validations::Callbacks
- Defined in:
- lib/subroutine/op.rb
Instance Attribute Summary collapse
-
#original_params ⇒ Object
readonly
Returns the value of attribute original_params.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
-
.field(*fields) ⇒ Object
(also: fields)
fields can be provided in the following way: field :field1, :field2 field :field3, :field4, default: ‘my default’.
- .ignore_error(*field_names) ⇒ Object (also: ignore_errors)
- .inherited(child) ⇒ Object
- .inputs_from(*ops) ⇒ Object
- .submit(*args) ⇒ Object
- .submit!(*args) ⇒ Object
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(inputs = {}) ⇒ Op
constructor
A new instance of Op.
-
#submit ⇒ Object
the action which should be invoked upon form submission (from the controller).
- #submit! ⇒ Object
Constructor Details
#initialize(inputs = {}) ⇒ Op
Returns a new instance of Op.
135 136 137 138 |
# File 'lib/subroutine/op.rb', line 135 def initialize(inputs = {}) @original_params = inputs.with_indifferent_access @params = sanitize_params(@original_params) end |
Instance Attribute Details
#original_params ⇒ Object (readonly)
Returns the value of attribute original_params.
131 132 133 |
# File 'lib/subroutine/op.rb', line 131 def original_params @original_params end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
132 133 134 |
# File 'lib/subroutine/op.rb', line 132 def params @params end |
Class Method Details
.field(*fields) ⇒ Object Also known as: fields
fields can be provided in the following way: field :field1, :field2 field :field3, :field4, default: ‘my default’
34 35 36 37 38 39 40 |
# File 'lib/subroutine/op.rb', line 34 def field(*fields) = fields. fields.each do |f| _field(f, ) end end |
.ignore_error(*field_names) ⇒ Object Also known as: ignore_errors
44 45 46 47 48 |
# File 'lib/subroutine/op.rb', line 44 def ignore_error(*field_names) field_names.each do |f| _ignore_errors(f) end end |
.inherited(child) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/subroutine/op.rb', line 59 def inherited(child) super child._fields = self._fields.dup child._error_map = self._error_map.dup child._error_ignores = self._error_ignores.dup end |
.inputs_from(*ops) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/subroutine/op.rb', line 51 def inputs_from(*ops) ops.each do |op| op._fields.each_pair do |field_name, | field(field_name, ) end end end |
.submit(*args) ⇒ Object
74 75 76 77 78 |
# File 'lib/subroutine/op.rb', line 74 def submit(*args) op = new(*args) op.submit op end |
.submit!(*args) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/subroutine/op.rb', line 67 def submit!(*args) op = new(*args) op.submit! op end |
Instance Method Details
#errors ⇒ Object
140 141 142 |
# File 'lib/subroutine/op.rb', line 140 def errors @filtered_errors ||= Subroutine::FilteredErrors.new(super) end |
#submit ⇒ Object
the action which should be invoked upon form submission (from the controller)
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/subroutine/op.rb', line 152 def submit observe_submission do validate_and_perform end rescue Exception => e if e.respond_to?(:record) inherit_errors(e.record) unless e.record == self false else raise e end end |
#submit! ⇒ Object
144 145 146 147 148 149 |
# File 'lib/subroutine/op.rb', line 144 def submit! unless submit raise ::Subroutine::Failure.new(self) end true end |