Class: Forte::DecisionCore

Inherits:
Object
  • Object
show all
Defined in:
lib/forte/decision_core.rb

Constant Summary

INITIAL_STATE =
:b13

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (DecisionCore) initialize(resource)

A new instance of DecisionCore



7
8
9
# File 'lib/forte/decision_core.rb', line 7

def initialize(resource)
  self.resource = resource
end

Instance Attribute Details

- resource

Returns the value of attribute resource



5
6
7
# File 'lib/forte/decision_core.rb', line 5

def resource
  @resource
end

Instance Method Details

- b10



55
56
57
58
59
60
61
62
63
# File 'lib/forte/decision_core.rb', line 55

def b10
  allowed_methods = resource.allowed_methods
  if allowed_methods.include?(request.method.to_s)
    :b9
  else
    response.headers['Allow'] = allowed_methods.join(', ')
    halt 405
  end
end

- b11



47
48
49
50
51
52
53
# File 'lib/forte/decision_core.rb', line 47

def b11
  if resource.request_uri_too_long?
    halt 414
  else
    :b10
  end
end

- b12



39
40
41
42
43
44
45
# File 'lib/forte/decision_core.rb', line 39

def b12
  if resource.known_methods.include?(request.method.to_s)
    :b11
  else
    halt 501
  end
end

- b13



31
32
33
34
35
36
37
# File 'lib/forte/decision_core.rb', line 31

def b13
  if resource.service_unavailable?
    halt 503
  else
    :b12
  end
end

- b3



113
114
115
116
117
118
119
120
# File 'lib/forte/decision_core.rb', line 113

def b3
  if request.options?
    resource.options
    halt 200
  else
    :c3
  end
end

- b4



105
106
107
108
109
110
111
# File 'lib/forte/decision_core.rb', line 105

def b4
  if resource.request_entity_too_large?
    halt 413
  else
    :b3
  end
end

- b5



97
98
99
100
101
102
103
# File 'lib/forte/decision_core.rb', line 97

def b5
  if request.content_type && !resource.known_mime_types.include?(request.content_type.mime_type)
    halt 415
  else
    :b4
  end
end

- b6



89
90
91
92
93
94
95
# File 'lib/forte/decision_core.rb', line 89

def b6
  if resource.valid_content_headers?
    :b5
  else
    halt 501
  end
end

- b7



81
82
83
84
85
86
87
# File 'lib/forte/decision_core.rb', line 81

def b7
  if resource.forbidden?
    halt 403
  else
    :b6
  end
end

- b8



73
74
75
76
77
78
79
# File 'lib/forte/decision_core.rb', line 73

def b8
  if resource.authorized?
    :b7
  else
    halt 401
  end
end

- b9



65
66
67
68
69
70
71
# File 'lib/forte/decision_core.rb', line 65

def b9
  if resource.malformed_request?
    halt 400
  else
    :b8
  end
end

- call



19
20
21
22
23
24
# File 'lib/forte/decision_core.rb', line 19

def call
  catch :halt do
    state = :b13
    loop { state = send(state) }
  end
end

- halt(status_code)



26
27
28
29
# File 'lib/forte/decision_core.rb', line 26

def halt(status_code)
  response.status_code = status_code
  throw :halt
end

- request



11
12
13
# File 'lib/forte/decision_core.rb', line 11

def request
  resource.request
end

- response



15
16
17
# File 'lib/forte/decision_core.rb', line 15

def response
  resource.response
end