Class: Servitium::Context

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks, ActiveModel::Naming, ActiveModel::Translation, I18n
Includes:
ContextModel
Defined in:
lib/servitium/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18n

t

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

#errorsObject (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, options = {})
  t(".#{attribute}", default: super)
end

Instance Method Details

#fail!(attr, message = :invalid, options = {}) ⇒ Object

Raises:



42
43
44
45
46
# File 'lib/servitium/context.rb', line 42

def fail!(attr, message = :invalid, options = {})
  @success = false
  merge_errors!(attr, message, options)
  raise ContextFailure, self
end

#failure?Boolean Also known as: fail?, failed?

Returns:

  • (Boolean)


35
36
37
# File 'lib/servitium/context.rb', line 35

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/servitium/context.rb', line 31

def success?
  @called && @success
end