Class: RubyApp::Session
Defined Under Namespace
Classes: Identity
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
configuration
exists?, method_missing
localize, translate
Constructor Details
#initialize(document = nil) ⇒ Session
Returns a new instance of Session.
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
31
32
33
|
# File 'lib/ruby_app/session.rb', line 31
def data
@data
end
|
#documents ⇒ Object
Returns the value of attribute documents.
30
31
32
|
# File 'lib/ruby_app/session.rb', line 30
def documents
@documents
end
|
#expires ⇒ Object
Returns the value of attribute expires.
28
29
30
|
# File 'lib/ruby_app/session.rb', line 28
def expires
@expires
end
|
#identity ⇒ Object
Returns the value of attribute identity.
33
34
35
|
# File 'lib/ruby_app/session.rb', line 33
def identity
@identity
end
|
#session_id ⇒ Object
Returns the value of attribute session_id.
27
28
29
|
# File 'lib/ruby_app/session.rb', line 27
def session_id
@session_id
end
|
Class Method Details
.generate_session_id(session) ⇒ Object
.get ⇒ Object
150
151
152
|
# File 'lib/ruby_app/session.rb', line 150
def self.get
Thread.current[:_session]
end
|
.get_scripts(path = String.interpolate { RubyApp::Session.configuration.scripts.path }) ⇒ Object
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/ruby_app/session.rb', line 206
def self.get_scripts(path = String.interpolate { RubyApp::Session.configuration.scripts.path })
scripts = []
Dir.new(path).each do |item|
unless item.start_with?('.')
_path = File.join(path, item)
if File.directory?(_path)
scripts += self.get_scripts(_path)
elsif _path =~ /\.rb/
name = _path.gsub(String.interpolate { RubyApp::Session.configuration.scripts.path }, '').gsub(/^\//, '').gsub(/\.rb/, '')
scripts.push({:name => name,
:url => "/quit?go=#{CGI.escape("/?script=#{name}")}"})
end
end
end
return scripts.sort { |a, b| a.name <=> b.name }
end
|
.get_session(session_id) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/ruby_app/session.rb', line 124
def self.get_session(session_id)
session = RubyApp::Session.sessions[session_id]
if session
unless session.expired?
session.reset_expiry!
return session
else
session.quit!
return nil
end
else
return nil
end
end
|
.load!(session_id = nil, script_path = nil) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'lib/ruby_app/session.rb', line 154
def self.load!(session_id = nil, script_path = nil)
session = RubyApp::Session.get_session(session_id)
unless session
session = Kernel.eval(RubyApp::Session.configuration._class).new
session.load_script!(script_path) if script_path
end
Thread.current[:_session] = session
end
|
.lock_sessions ⇒ Object
118
119
120
121
122
|
# File 'lib/ruby_app/session.rb', line 118
def self.lock_sessions
( @@_lock ||= ::Mutex.new ).synchronize do
yield
end
end
|
.sessions ⇒ Object
114
115
116
|
# File 'lib/ruby_app/session.rb', line 114
def self.sessions
return @@_sessions ||= {}
end
|
.stop_thread! ⇒ Object
198
199
200
201
202
203
204
|
# File 'lib/ruby_app/session.rb', line 198
def self.stop_thread!
if @@_thread ||= nil
RubyApp::Log.debug(RubyApp::Log.prefix(self, __method__))
@@_thread.exit
@@_thread = nil
end
end
|
.unload! ⇒ Object
163
164
165
|
# File 'lib/ruby_app/session.rb', line 163
def self.unload!
Thread.current[:_session] = nil
end
|
Instance Method Details
#add_step!(_class, &block) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/ruby_app/session.rb', line 75
def add_step!(_class, &block)
caller = Kernel.caller.first.split(':')
@steps.push({:_class => _class,
:file => caller[0].gsub(String.interpolate { RubyApp::Session.configuration.scripts.path }, '').gsub(/^\//, ''),
:line => caller[1].to_i,
:block => block})
end
|
#document ⇒ Object
52
53
54
|
# File 'lib/ruby_app/session.rb', line 52
def document
return @documents.last
end
|
#expired? ⇒ Boolean
60
61
62
|
# File 'lib/ruby_app/session.rb', line 60
def expired?
return @expires <= Time.now
end
|
#load_script!(path) ⇒ Object
70
71
72
73
|
# File 'lib/ruby_app/session.rb', line 70
def load_script!(path)
_path = File.join(String.interpolate { RubyApp::Session.configuration.scripts.path }, "#{path}.rb")
Kernel.eval(File.read(_path), self.send(:binding), _path)
end
|
#process_event!(event) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/ruby_app/session.rb', line 83
def process_event!(event)
event.process!
if RubyApp::Session.configuration.scripts.enabled
step = @steps[@steps_index]
if step
begin
if event.is_a?(step._class)
@steps_index += 1
RubyApp::Log.duration(RubyApp::Log::INFO, "STEP #{step.file}:#{step.line}") do
step.block.call(event)
end
if @steps_index == @steps.length
RubyApp::Log.info("STEP Completed #{@steps.length} steps")
end
end
rescue => exception
RubyApp::Log.info("STEP Exception occurred at #{step.file}:#{step.line}")
@steps_index = @steps.length
raise
end
end
end
end
|
#reset_script! ⇒ Object
110
111
112
|
# File 'lib/ruby_app/session.rb', line 110
def reset_script!
@steps_index = 0
end
|