Class: Webmachine::Decision::FSM
- Inherits:
-
Object
- Object
- Webmachine::Decision::FSM
- 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
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(resource, request, response) ⇒ FSM
constructor
A new instance of FSM.
-
#run ⇒ Object
Processes the request, iteratively invoking the decision methods in Flow.
Methods included from Translation
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.
18 19 20 21 22 |
# File 'lib/webmachine/decision/fsm.rb', line 18 def initialize(resource, request, response) @resource, @request, @response = resource, request, response @metadata = {} super end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
16 17 18 |
# File 'lib/webmachine/decision/fsm.rb', line 16 def @metadata end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
16 17 18 |
# File 'lib/webmachine/decision/fsm.rb', line 16 def request @request end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
16 17 18 |
# File 'lib/webmachine/decision/fsm.rb', line 16 def resource @resource end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/webmachine/decision/fsm.rb', line 16 def response @response end |
Instance Method Details
#run ⇒ Object
Processes the request, iteratively invoking the decision methods in Webmachine::Decision::Flow.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/webmachine/decision/fsm.rb', line 25 def run state = Flow::START trace_request(request) loop do trace_decision(state) result = handle_exceptions { send(state) } case result when Fixnum # 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.) ensure trace_response(response) end |