Module: Comandor
- Defined in:
- lib/comandor.rb,
lib/comandor/version.rb
Overview
Service Objects
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
'0.1.4'
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
-
.extended(base) ⇒ Object
Callback on ‘extend Comandor`.
Instance Method Summary collapse
-
#error(key, message) ⇒ self
Add new error to key array.
-
#errors ⇒ Hash<Symbol => Array>
List of errors.
-
#fail? ⇒ Boolean
(also: #failed?)
Are we failed?.
- #perform(*args, &block) ⇒ self
-
#success? ⇒ Boolean
Are we done here?.
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/comandor.rb', line 7 def result @result end |
Class Method Details
.extended(base) ⇒ Object
Callback on ‘extend Comandor`
10 11 12 13 |
# File 'lib/comandor.rb', line 10 def self.extended(base) base.prepend(self) base.extend(ClassMethods) end |
Instance Method Details
#error(key, message) ⇒ self
Add new error to key array
55 56 57 58 59 60 61 62 63 |
# File 'lib/comandor.rb', line 55 def error(key, ) errors[key] ||= [] if .is_a? Array errors[key] = errors[key] + else errors[key] << end self end |
#errors ⇒ Hash<Symbol => Array>
List of errors
80 81 82 |
# File 'lib/comandor.rb', line 80 def errors @errors ||= {} end |
#fail? ⇒ Boolean Also known as: failed?
Are we failed?
73 74 75 |
# File 'lib/comandor.rb', line 73 def fail? done? && errors? end |
#perform(*args, &block) ⇒ self
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/comandor.rb', line 38 def perform(*args, &block) raise NoMethodError unless defined?(:perform) if self.class.transaction_klass && self.class.transaction_method @result = Object.const_get(self.class.transaction_klass).send self.class.transaction_method.to_sym do super end else @result = super end @done = true self end |
#success? ⇒ Boolean
Are we done here?
67 68 69 |
# File 'lib/comandor.rb', line 67 def success? done? && !errors? end |