Class: Specify::Session

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/specify/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, collection) ⇒ Session

Creates an instance.



13
14
15
16
17
18
19
# File 'lib/specify/session.rb', line 13

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

#activeObject (readonly)

Returns the value of attribute active



10
11
12
# File 'lib/specify/session.rb', line 10

def active
  @active
end

#collectionObject (readonly)

Returns the value of attribute collection



10
11
12
# File 'lib/specify/session.rb', line 10

def collection
  @collection
end

#disciplineObject (readonly)

Returns the value of attribute discipline



10
11
12
# File 'lib/specify/session.rb', line 10

def discipline
  @discipline
end

#divisionObject (readonly)

Returns the value of attribute division



10
11
12
# File 'lib/specify/session.rb', line 10

def division
  @division
end

#userObject (readonly)

Returns the value of attribute user



10
11
12
# File 'lib/specify/session.rb', line 10

def user
  @user
end

Instance Method Details

#closeObject

-> Session Closes the Session; logs the instance's user out.



30
31
32
33
34
35
36
# File 'lib/specify/session.rb', line 30

def close
  @user.log_out
  @active = false
  changed
  notify_observers(self)
  self
end

#inspectObject

-> String Returns a string containing a human-readable representation of Session.



23
24
25
26
# File 'lib/specify/session.rb', line 23

def inspect
  "#{self} specify user: #{@user}"\
  ", collection: #{@collection}, open: #{@active}"
end

#openObject

-> Session Opens the Session; logs the instance's user in to the instance's collection.



41
42
43
44
45
# File 'lib/specify/session.rb', line 41

def open
  @user.(@collection)
  @active = true
  self
end

#open?Boolean

-> true or false Returns true if the Session is open.

Returns:

  • (Boolean)


49
50
51
# File 'lib/specify/session.rb', line 49

def open?
  @active
end

#session_agentObject

-> Model::Agent Returns the Model::Agent for the Model::User in the Model::Division that _@collection_ belongs to.



56
57
58
# File 'lib/specify/session.rb', line 56

def session_agent
  user.logged_in_agent
end