Class: GL::Context

Inherits:
OpenStruct
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/gl/command/context.rb

Overview

rubocop:disable Style/OpenStructUse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Context

Returns a new instance of Context.



18
19
20
21
# File 'lib/gl/command/context.rb', line 18

def initialize(args)
  super(args)
  @errors = ActiveModel::Errors.new(self)
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



9
10
11
# File 'lib/gl/command/context.rb', line 9

def errors
  @errors
end

Class Method Details

.factory(context = {}) ⇒ Object

Raises:



11
12
13
14
15
16
# File 'lib/gl/command/context.rb', line 11

def self.factory(context = {})
  return context if context.is_a?(Context)
  raise NotAContextError, 'Arguments are not a Context.' unless context.respond_to?(:each_pair)

  Context.new(context)
end

Instance Method Details

#fail!Object



23
24
25
# File 'lib/gl/command/context.rb', line 23

def fail!
  @failure = true
end

#failure?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/gl/command/context.rb', line 27

def failure?
  @failure || false
end

#inspectObject



36
37
38
# File 'lib/gl/command/context.rb', line 36

def inspect
  "<GL::Context success:#{success?} errors:#{@errors.full_messages} data:#{to_h}>"
end

#success?Boolean Also known as: successful?

Returns:

  • (Boolean)


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

def success?
  !failure?
end