Class: Webmachine::Decision::FSM

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

Overview

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

Constant Summary

Constant Summary

Constants included from QuotedString

QuotedString::QS_ANCHORED, QuotedString::QUOTED_STRING

Constants included from Flow

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 Helpers

#accept_helper, #add_caching_headers, #body_is_fixed_length?, #encode_body, #encode_body_if_set, #ensure_content_length, #ensure_date_header, #has_response_body?, #set_content_length, #variances

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

- (FSM) initialize(resource, request, response)

Returns a new instance of FSM



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

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

Instance Attribute Details

- (Object) metadata (readonly)

Returns the value of attribute metadata



13
14
15
# File 'lib/webmachine/decision/fsm.rb', line 13

def 
  @metadata
end

- (Object) request (readonly)

Returns the value of attribute request



13
14
15
# File 'lib/webmachine/decision/fsm.rb', line 13

def request
  @request
end

- (Object) resource (readonly)

Returns the value of attribute resource



13
14
15
# File 'lib/webmachine/decision/fsm.rb', line 13

def resource
  @resource
end

- (Object) response (readonly)

Returns the value of attribute response



13
14
15
# File 'lib/webmachine/decision/fsm.rb', line 13

def response
  @response
end

Instance Method Details

- (Object) run

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webmachine/decision/fsm.rb', line 22

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 Exception => e
  Webmachine.render_error(500, request, response, :message => e.message)
ensure
  trace_response(response)
end