Class: Specify::Session
- Inherits:
-
Object
- Object
- Specify::Session
- Includes:
- Observable
- Defined in:
- lib/specify/session.rb
Overview
A Session is responsible for logging an existing Specify::Model::User in and out of a Specify::Model::Collection. Session objects are used to set the #created_by and #modified_by attributes for any record created or updated to the session #user.
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
trueif the session is open (the #user is logged in),falseotherwise. -
#collection ⇒ Object
readonly
The Specify::Model::Collection that #user is logged in to during the life span of the session.
-
#discipline ⇒ Object
readonly
The Specify::Model::Discipline that #user is logged in to during the life span of the session.
-
#division ⇒ Object
readonly
The Specify::Model::Division that #collection and #discipline belong to.
-
#user ⇒ Object
readonly
The Specify::Model::User that is logged in to #collection during the session.
Instance Method Summary collapse
-
#close ⇒ Object
Closes this session, logs #user out of #collection.
-
#initialize(user, collection) ⇒ Session
constructor
Returns a new Session.
-
#inspect ⇒ Object
Creates a string representation of
self. -
#open ⇒ Object
Opens this session, logs #user in to #collection.
-
#open? ⇒ Boolean
Returns
trueif this session is currently open. -
#session_agent ⇒ Object
Returns the Specify::Model::Agent for #user in #division.
Constructor Details
#initialize(user, collection) ⇒ Session
Returns a new Session.
user is a String with an existing Specify::Model::User#name.
collection is a String with and existing Specify::Model::Collection#name.
37 38 39 40 41 42 43 |
# File 'lib/specify/session.rb', line 37 def initialize(user, collection) @user = Model::User.first(Name: user) @collection = Model::Collection.first(CollectionName: collection) @discipline = @collection.discipline @division = @discipline.division @active = false end |
Instance Attribute Details
#active ⇒ Object (readonly)
true if the session is open (the #user is logged in), false otherwise.
14 15 16 |
# File 'lib/specify/session.rb', line 14 def active @active end |
#collection ⇒ Object (readonly)
The Specify::Model::Collection that #user is logged in to during the life span of the session.
18 19 20 |
# File 'lib/specify/session.rb', line 18 def collection @collection end |
#discipline ⇒ Object (readonly)
The Specify::Model::Discipline that #user is logged in to during the life span of the session.
22 23 24 |
# File 'lib/specify/session.rb', line 22 def discipline @discipline end |
#division ⇒ Object (readonly)
The Specify::Model::Division that #collection and #discipline belong to.
25 26 27 |
# File 'lib/specify/session.rb', line 25 def division @division end |
#user ⇒ Object (readonly)
The Specify::Model::User that is logged in to #collection during the session.
29 30 31 |
# File 'lib/specify/session.rb', line 29 def user @user end |
Instance Method Details
#close ⇒ Object
Closes this session, logs #user out of #collection.
52 53 54 55 56 57 58 |
# File 'lib/specify/session.rb', line 52 def close @user.log_out @active = false changed notify_observers(self) self end |
#inspect ⇒ Object
Creates a string representation of self.
46 47 48 49 |
# File 'lib/specify/session.rb', line 46 def inspect "#{self} specify user: #{@user}"\ ", collection: #{@collection}, open: #{@active}" end |
#open ⇒ Object
Opens this session, logs #user in to #collection.
61 62 63 64 65 |
# File 'lib/specify/session.rb', line 61 def open @user.log_in(@collection) @active = true self end |
#open? ⇒ Boolean
Returns true if this session is currently open.
68 69 70 |
# File 'lib/specify/session.rb', line 68 def open? @active end |
#session_agent ⇒ Object
Returns the Specify::Model::Agent for #user in #division.
73 74 75 |
# File 'lib/specify/session.rb', line 73 def session_agent user.logged_in_agent end |