Class: Canals::Session
- Inherits:
-
Object
- Object
- Canals::Session
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/canals/session.rb
Constant Summary collapse
- BASIC_FIELDS =
[:name, :pid, :socket]
Instance Method Summary collapse
- #add(session, save = true) ⇒ Object
- #alive?(session_id) ⇒ Boolean
- #del(name, save = true) ⇒ Object
- #each(&block) ⇒ Object
- #each_obj(&block) ⇒ Object
- #empty? ⇒ Boolean
- #get(session_id) ⇒ Object
- #get_obj(session_id) ⇒ Object
- #has?(session_id) ⇒ Boolean
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #save! ⇒ Object
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
13 14 15 |
# File 'lib/canals/session.rb', line 13 def initialize @session = load_session(session_file) end |
Instance Method Details
#add(session, save = true) ⇒ Object
31 32 33 34 |
# File 'lib/canals/session.rb', line 31 def add(session, save=true) @session.push(session) save! if save end |
#alive?(session_id) ⇒ Boolean
62 63 64 65 |
# File 'lib/canals/session.rb', line 62 def alive?(session_id) sess = get(session_id) File.exist?(sess[:socket]) end |
#del(name, save = true) ⇒ Object
36 37 38 39 |
# File 'lib/canals/session.rb', line 36 def del(name, save=true) @session.delete_if{ |s| s[:name] == name } save! if save end |
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/canals/session.rb', line 19 def each(&block) @session.each(&block) end |
#each_obj(&block) ⇒ Object
23 24 25 |
# File 'lib/canals/session.rb', line 23 def each_obj(&block) @session.map{|sess| CanalOptions.new(fill_from_repository(sess))}.each(&block) end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/canals/session.rb', line 27 def empty? @session.empty? end |
#get(session_id) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/canals/session.rb', line 41 def get(session_id) sess = nil case session_id when Numeric sess = @session.find{ |s| s[:pid] == session_id } when String sess = @session.find{ |s| s[:name] == session_id } end fill_from_repository(sess) if sess end |
#get_obj(session_id) ⇒ Object
52 53 54 55 56 |
# File 'lib/canals/session.rb', line 52 def get_obj(session_id) sess = get(session_id) return nil if sess.nil? CanalOptions.new(sess) end |
#has?(session_id) ⇒ Boolean
58 59 60 |
# File 'lib/canals/session.rb', line 58 def has?(session_id) get(session_id) != nil end |