Module: Leadlight::Representation

Extended by:
Forwardable
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__.



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

def __location__
  @__location__
end

#__request__Object

Returns the value of attribute __request__.



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

def __request__
  @__request__
end

#__response__Object

Returns the value of attribute __response__.



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

def __response__
  @__response__
end

#__service__Object

Returns the value of attribute __service__.



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

def __service__
  @__service__
end

Instance Method Details

#__captures__Object



59
60
61
# File 'lib/leadlight/representation.rb', line 59

def __captures__
  @__captures__ ||= {}
end


51
52
53
# File 'lib/leadlight/representation.rb', line 51

def __link__
  __request__.link
end

#__request_params__Object



55
56
57
# File 'lib/leadlight/representation.rb', line 55

def __request_params__
  __request__.params
end

#apply_all_tintsObject



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

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

#exception(message = exception_message) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/leadlight/representation.rb', line 32

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(__request__, exception_message)
end

#exception_messageObject



41
42
43
# File 'lib/leadlight/representation.rb', line 41

def exception_message
  http_status_message
end

#http_status_messageObject



45
46
47
48
49
# File 'lib/leadlight/representation.rb', line 45

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

#initialize_representation(service, location, response, request) ⇒ Object

fattr(:__captures__) { {} }



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

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