Class: ServicePattern::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/service_pattern/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Response

Returns a new instance of Response.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/service_pattern/response.rb', line 4

def initialize(args)
  @errors = args[:errors] || []
  @result = args[:result]

  if args.key?(:success)
    @success = args.fetch(:success)
  elsif args.key?(:errors) && @errors.any?
    @success = false
  elsif @result
    @success = true
  else
    raise "Couldn't figure out if it was a success"
  end
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



2
3
4
# File 'lib/service_pattern/response.rb', line 2

def errors
  @errors
end

#resultObject (readonly)

Returns the value of attribute result.



2
3
4
# File 'lib/service_pattern/response.rb', line 2

def result
  @result
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/service_pattern/response.rb', line 19

def success?
  @success
end