Class: RubyApp::Session
- Inherits:
-
Object
- Object
- RubyApp::Session
- Extended by:
- Mixins::DelegateMixin, Mixins::TranslateMixin
- Includes:
- Mixins::ConfigurationMixin, Mixins::HashMixin
- Defined in:
- lib/ruby_app/session.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Identity
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
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::ConfigurationMixin
Methods included from Mixins::HashMixin
Constructor Details
#initialize(session_id, page = nil, data = {}) ⇒ Session
Returns a new instance of Session.
29 30 31 32 33 34 35 36 37 |
# File 'lib/ruby_app/session.rb', line 29 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 (readonly)
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.
27 28 29 |
# File 'lib/ruby_app/session.rb', line 27 def identity @identity end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
26 27 28 |
# File 'lib/ruby_app/session.rb', line 26 def pages @pages end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
26 27 28 |
# File 'lib/ruby_app/session.rb', line 26 def session_id @session_id end |
Class Method Details
.create! ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ruby_app/session.rb', line 76 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) if block_given? begin yield ensure self.destroy! end end end |
.destroy! ⇒ Object
88 89 90 |
# File 'lib/ruby_app/session.rb', line 88 def self.destroy! Thread.current[:_session] = nil end |
.get ⇒ Object
72 73 74 |
# File 'lib/ruby_app/session.rb', line 72 def self.get Thread.current[:_session] end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 |
# File 'lib/ruby_app/session.rb', line 39 def [](key) @data[key] end |
#[]=(key, value) ⇒ Object
43 44 45 |
# File 'lib/ruby_app/session.rb', line 43 def []=(key, value) @data[key] = value end |
#quit ⇒ Object
68 69 70 |
# File 'lib/ruby_app/session.rb', line 68 def quit RubyApp::Request.env['rack.session.options'][:drop] = true if RubyApp::Request.env['rack.session.options'] end |
#show_dialog(event, dialog, &block) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_app/session.rb', line 47 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 |