Class: RubyApp::Session
- Inherits:
-
Object
- Object
- RubyApp::Session
- Extended by:
- Mixins::DelegateMixin, Mixins::TranslateMixin
- Includes:
- Mixins::ConfigureMixin, Mixins::HashMixin
- Defined in:
- lib/ruby_app/session.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Identity
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(session_id, page = nil, data = {}) ⇒ Session
constructor
A new instance of Session.
- #quit ⇒ Object
- #show_dialog(event, dialog, &block) ⇒ Object
Methods included from Mixins::DelegateMixin
Methods included from Mixins::TranslateMixin
Methods included from Mixins::ConfigureMixin
Methods included from Mixins::HashMixin
Constructor Details
#initialize(session_id, page = nil, data = {}) ⇒ Session
Returns a new instance of Session.
28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_app/session.rb', line 28 def initialize(session_id, page = nil, data = {}) require 'ruby_app/elements/pages/default_page' @session_id = session_id @pages = [] @pages.push(page || RubyApp::Elements::Pages::DefaultPage.new) @dialogs = [] @data = data @identity = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RubyApp::Mixins::HashMixin
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
26 27 28 |
# File 'lib/ruby_app/session.rb', line 26 def data @data end |
#identity ⇒ Object
Returns the value of attribute identity.
26 27 28 |
# File 'lib/ruby_app/session.rb', line 26 def identity @identity end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
25 26 27 |
# File 'lib/ruby_app/session.rb', line 25 def pages @pages end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
25 26 27 |
# File 'lib/ruby_app/session.rb', line 25 def session_id @session_id end |
Class Method Details
.create! ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_app/session.rb', line 75 def self.create! RubyApp::Request.session[:_initialize] = true Thread.current[:_session] = RubyApp::Request.session[:_session] ||= RubyApp::Application..session_class.new(RubyApp::Request.env['rack.session.options'] ? RubyApp::Request.env['rack.session.options'][:id] : nil, nil, RubyApp::Request.query) if block_given? begin yield ensure self.destroy! end end end |
.destroy! ⇒ Object
87 88 89 |
# File 'lib/ruby_app/session.rb', line 87 def self.destroy! Thread.current[:_session] = nil end |
.get ⇒ Object
71 72 73 |
# File 'lib/ruby_app/session.rb', line 71 def self.get Thread.current[:_session] end |
Instance Method Details
#[](key) ⇒ Object
38 39 40 |
# File 'lib/ruby_app/session.rb', line 38 def [](key) @data[key] end |
#[]=(key, value) ⇒ Object
42 43 44 |
# File 'lib/ruby_app/session.rb', line 42 def []=(key, value) @data[key] = value end |
#quit ⇒ Object
67 68 69 |
# File 'lib/ruby_app/session.rb', line 67 def quit RubyApp::Request.env['rack.session.options'][:drop] = true if RubyApp::Request.env['rack.session.options'] end |
#show_dialog(event, dialog, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_app/session.rb', line 46 def show_dialog(event, dialog, &block) @dialogs.push(dialog) if block_given? and block.arity == 1 dialog.shown do |element, _event| yield _event _event.hide_dialog(element) end end dialog.hidden do |element, _event| if block_given? and block.arity == 2 yield _event, dialog.response end @dialogs.delete(dialog) end event.show_dialog(dialog) end |