Class: Cuttlebone::Session
- Inherits:
-
Object
- Object
- Cuttlebone::Session
show all
- Defined in:
- lib/cuttlebone/session.rb
Defined Under Namespace
Modules: SessionCollectionExtensions
Classes: NotFound
Constant Summary
collapse
- @@sessions =
{}
- @@default_stack_objects =
[]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*stack_objects) ⇒ Session
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cuttlebone/session.rb', line 35
def initialize *stack_objects
options = stack_objects.
@id = options[:id] || Digest::SHA1.hexdigest(Time.now.to_s + Time.now.usec.to_s + rand(1000).to_s)
@@default_stack_objects.each { |so| stack_objects << (so.dup rescue so) } if stack_objects.empty?
@stack ||= stack_objects.map{ |o| Cuttlebone::Controller.new(self, o) }
rescue Cuttlebone::InvalidContextError => e
@internal_error = %{Context initialization failed for #{e.context.inspect}!}
rescue => e
@internal_error = %{Internal error occured: #{e.message} (#{e.class})}
ensure
@stack ||= []
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
48
49
50
|
# File 'lib/cuttlebone/session.rb', line 48
def id
@id
end
|
#internal_error ⇒ Object
Returns the value of attribute internal_error.
48
49
50
|
# File 'lib/cuttlebone/session.rb', line 48
def internal_error
@internal_error
end
|
#stack ⇒ Object
Returns the value of attribute stack.
48
49
50
|
# File 'lib/cuttlebone/session.rb', line 48
def stack
@stack
end
|
Class Method Details
.sessions ⇒ Object
31
32
33
|
# File 'lib/cuttlebone/session.rb', line 31
def self.sessions
@@sessions
end
|
.set_default(*stack_objects) ⇒ Object
27
28
29
|
# File 'lib/cuttlebone/session.rb', line 27
def self.set_default *stack_objects
@@default_stack_objects = stack_objects
end
|
Instance Method Details
#active_context ⇒ Object
50
51
52
|
# File 'lib/cuttlebone/session.rb', line 50
def active_context
stack.last
end
|
#call(command) ⇒ Object
56
57
58
|
# File 'lib/cuttlebone/session.rb', line 56
def call command
process command
end
|
#terminated? ⇒ Boolean
60
61
62
|
# File 'lib/cuttlebone/session.rb', line 60
def terminated?
stack.empty?
end
|