Class: RubyApp::Session

Inherits:
Object
  • Object
show all
Extended by:
Mixins::DelegateMixin, Mixins::TranslateMixin
Includes:
Mixins::ConfigureMixin, Mixins::HashMixin
Defined in:
lib/ruby_app/session.rb

Direct Known Subclasses

_APPLICATION_UPCODE_::Session

Defined Under Namespace

Classes: Identity

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::DelegateMixin

method_missing

Methods included from Mixins::TranslateMixin

localize, translate

Methods included from Mixins::ConfigureMixin

#configure

Methods included from Mixins::HashMixin

#method_missing

Constructor Details

#initialize(page = nil) ⇒ Session

Returns a new instance of Session.



33
34
35
36
37
38
39
# File 'lib/ruby_app/session.rb', line 33

def initialize(page = nil)
  require 'ruby_app/elements/pages/default_page'
  @pages = [ page || RubyApp::Elements::Pages::DefaultPage.new ]
  @dialogs = []
  @identity = nil
  @data = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubyApp::Mixins::HashMixin

Instance Attribute Details

#dataObject

Returns the value of attribute data.



31
32
33
# File 'lib/ruby_app/session.rb', line 31

def data
  @data
end

#identityObject

Returns the value of attribute identity.



31
32
33
# File 'lib/ruby_app/session.rb', line 31

def identity
  @identity
end

#pagesObject (readonly)

Returns the value of attribute pages.



30
31
32
# File 'lib/ruby_app/session.rb', line 30

def pages
  @pages
end

Class Method Details

.create!Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/ruby_app/session.rb', line 78

def self.create!
  Thread.current[:_session] = RubyApp::Request.session[:_session] ||= RubyApp::Application.options.session_class.new
  if block_given?
    begin
      yield
    ensure
      self.destroy!
    end
  end
end

.destroy!Object



89
90
91
# File 'lib/ruby_app/session.rb', line 89

def self.destroy!
  Thread.current[:_session] = nil
end

.getObject



74
75
76
# File 'lib/ruby_app/session.rb', line 74

def self.get
  Thread.current[:_session]
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
# File 'lib/ruby_app/session.rb', line 41

def [](key)
  @data[key]
end

#[]=(key, value) ⇒ Object



45
46
47
# File 'lib/ruby_app/session.rb', line 45

def []=(key, value)
  @data[key] = value
end

#quitObject



70
71
72
# File 'lib/ruby_app/session.rb', line 70

def quit
  RubyApp::Request.env['rack.session.options'][:drop] = true
end

#show(event, dialog, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ruby_app/session.rb', line 49

def show(event, dialog, &block)

  @dialogs.push(dialog)

  if block_given? and block.arity == 1
    dialog.shown do |element, _event|
      yield _event
      _event.hide(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)

end