Class: Cuttlebone::Session
- Inherits:
-
Object
- Object
- Cuttlebone::Session
- Defined in:
- lib/cuttlebone/session.rb
Defined Under Namespace
Modules: SessionCollectionExtensions Classes: NotFound
Constant Summary collapse
- @@sessions =
{}
- @@default_stack_objects =
[]
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#internal_error ⇒ Object
readonly
Returns the value of attribute internal_error.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Class Method Summary collapse
Instance Method Summary collapse
- #active_context ⇒ Object
- #call(command) ⇒ Object
-
#initialize(*stack_objects) ⇒ Session
constructor
A new instance of Session.
- #terminated? ⇒ Boolean
Constructor Details
#initialize(*stack_objects) ⇒ Session
Returns a new instance of Session.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cuttlebone/session.rb', line 35 def initialize *stack_objects = stack_objects. @id = [:id] || Digest::SHA1.hexdigest(Time.now.to_s + Time.now.usec.to_s + rand(1000).to_s) # TODO FIXME @@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.} (#{e.class})} ensure @stack ||= [] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
48 49 50 |
# File 'lib/cuttlebone/session.rb', line 48 def id @id end |
#internal_error ⇒ Object (readonly)
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 (readonly)
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 |