Module: Leadlight::Representation

Defined in:
lib/leadlight/representation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#__location__Object

Returns the value of attribute __location__.



8
9
10
# File 'lib/leadlight/representation.rb', line 8

def __location__
  @__location__
end

#__response__Object

Returns the value of attribute __response__.



9
10
11
# File 'lib/leadlight/representation.rb', line 9

def __response__
  @__response__
end

#__service__Object

Returns the value of attribute __service__.



7
8
9
# File 'lib/leadlight/representation.rb', line 7

def __service__
  @__service__
end

Instance Method Details

#apply_all_tintsObject



18
19
20
21
22
# File 'lib/leadlight/representation.rb', line 18

def apply_all_tints
  __service__.tints.inject(self, &:extend)
  __apply_tint__
  self
end

#exception(message = exception_message) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/leadlight/representation.rb', line 24

def exception(message=exception_message)
  return super if defined?(super)
  case __response__.status.to_i
  when 404 then ResourceNotFound
  when (400..499) then ClientError
  when (500..599) then ServerError
  end.new(__response__, exception_message)
end

#exception_messageObject



33
34
35
# File 'lib/leadlight/representation.rb', line 33

def exception_message
  http_status_message
end

#http_status_messageObject



37
38
39
40
41
# File 'lib/leadlight/representation.rb', line 37

def http_status_message
  __response__.env.fetch(:response_headers).fetch('status'){
    status.to_s
  }
end

#initialize_representation(service, location, response) ⇒ Object



11
12
13
14
15
16
# File 'lib/leadlight/representation.rb', line 11

def initialize_representation(service, location, response)
  self.__service__ = service
  self.__location__ = location
  self.__response__ = response
  self
end