Class: Servitium::Context
- Inherits:
-
Object
- Object
- Servitium::Context
- Extended by:
- ActiveModel::Callbacks, ActiveModel::Naming, ActiveModel::Translation, I18n
- Includes:
- ContextModel
- Defined in:
- lib/servitium/context.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
- #fail!(attr, message = :invalid, options = {}) ⇒ Object
- #failure? ⇒ Boolean (also: #fail?, #failed?)
-
#initialize(*args) ⇒ Context
constructor
A new instance of Context.
- #success? ⇒ Boolean
Methods included from I18n
Constructor Details
#initialize(*args) ⇒ Context
Returns a new instance of Context.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/servitium/context.rb', line 20 def initialize(*args) @success = true @called = false @errors = ActiveModel::Errors.new(self) @subcontexts = {} run_callbacks :initialize do super(*args) end end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
16 17 18 |
# File 'lib/servitium/context.rb', line 16 def errors @errors end |
Class Method Details
.human_attribute_name(attribute, options = {}) ⇒ Object
65 66 67 |
# File 'lib/servitium/context.rb', line 65 def human_attribute_name(attribute, = {}) t(".#{attribute}", default: super) end |
Instance Method Details
#fail!(attr, message = :invalid, options = {}) ⇒ Object
42 43 44 45 46 |
# File 'lib/servitium/context.rb', line 42 def fail!(attr, = :invalid, = {}) @success = false merge_errors!(attr, , ) raise ContextFailure, self end |
#failure? ⇒ Boolean Also known as: fail?, failed?
35 36 37 |
# File 'lib/servitium/context.rb', line 35 def failure? !success? end |
#success? ⇒ Boolean
31 32 33 |
# File 'lib/servitium/context.rb', line 31 def success? @called && @success end |