Class: Webmachine::Decision::FSM

Inherits:
Object
  • Object
show all
Includes:
Flow, Helpers, Trace::FSM, Translation
Defined in:
lib/webmachine/decision/fsm.rb

Overview

Implements the finite-state machine described by the Webmachine sequence diagram.

Constant Summary

Constants included from QuotedString

QuotedString::QS_ANCHORED, QuotedString::QUOTED_STRING

Constants included from Flow

Webmachine::Decision::Flow::CONTENT, Webmachine::Decision::Flow::START, Webmachine::Decision::Flow::VERSION

Constants included from Conneg

Conneg::HAS_ENCODING

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Translation

#t

Methods included from Trace::FSM

#trace?, #trace_decision, #trace_request, #trace_response

Methods included from Helpers

#accept_helper, #add_caching_headers, #body_is_fixed_length?, #encode_body, #encode_body_if_set, #has_response_body?, #variances

Methods included from HeaderNegotiation

#ensure_content_length, #ensure_date_header

Methods included from QuotedString

#escape_quotes, #quote, #unescape_quotes, #unquote

Methods included from Flow

#b10, #b11, #b12, #b13, #b3, #b4, #b5, #b6, #b7, #b8, #b9, #b9a, #b9b, #c3, #c4, #d4, #d5, #decision_test, #e5, #e6, #f6, #f7, #g11, #g7, #g8, #g9, #h10, #h11, #h12, #h7, #i12, #i13, #i4, #i7, #j18, #k13, #k5, #k7, #l13, #l14, #l15, #l17, #l5, #l7, #m16, #m20, #m20b, #m5, #m7, #n11, #n16, #n5, #o14, #o16, #o18, #o18b, #o20, #p11, #p3

Methods included from Conneg

#choose_charset, #choose_encoding, #choose_language, #choose_media_type, #do_choose, #language_match

Constructor Details

#initialize(resource, request, response) ⇒ FSM

Returns a new instance of FSM.



19
20
21
22
23
# File 'lib/webmachine/decision/fsm.rb', line 19

def initialize(resource, request, response)
  @resource, @request, @response = resource, request, response
  @metadata = {}
  super
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



17
18
19
# File 'lib/webmachine/decision/fsm.rb', line 17

def 
  @metadata
end

#requestObject (readonly)

Returns the value of attribute request.



17
18
19
# File 'lib/webmachine/decision/fsm.rb', line 17

def request
  @request
end

#resourceObject (readonly)

Returns the value of attribute resource.



17
18
19
# File 'lib/webmachine/decision/fsm.rb', line 17

def resource
  @resource
end

#responseObject (readonly)

Returns the value of attribute response.



17
18
19
# File 'lib/webmachine/decision/fsm.rb', line 17

def response
  @response
end

Instance Method Details

#runObject

Processes the request, iteratively invoking the decision methods in Webmachine::Decision::Flow.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/webmachine/decision/fsm.rb', line 26

def run
  state = Flow::START
  trace_request(request)
  loop do
    trace_decision(state)
    result = handle_exceptions { send(state) }
    case result
    when Integer # Response code
      respond(result)
      break
    when Symbol # Next state
      state = result
    else # You bwoke it
      raise InvalidResource, t('fsm_broke', :state => state, :result => result.inspect)
    end
  end
rescue => e
  Webmachine.render_error(500, request, response, :message => e.message)
ensure
  trace_response(response)
end