Class: Rdomino::Session
- Inherits:
-
Object
- Object
- Rdomino::Session
- Defined in:
- lib/rdomino/session.rb
Class Attribute Summary collapse
-
.session ⇒ Object
readonly
Returns the value of attribute session.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Class Method Summary collapse
- .addressbooks ⇒ Object
-
.get(env = ((defined? RAILS_ENV) ? RAILS_ENV.downcase : "test"), user = nil) ⇒ Object
This is the entrypoint to the library.
- .locations ⇒ Object
- .prepare_notes_ini(user) ⇒ Object
- .private_addressbooks ⇒ Object
- .reload! ⇒ Object
Instance Method Summary collapse
- #[](name, view = nil, key = nil) ⇒ Object
-
#initialize(env) ⇒ Session
constructor
A new instance of Session.
- #server_path(name) ⇒ Object
Constructor Details
#initialize(env) ⇒ Session
Returns a new instance of Session.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rdomino/session.rb', line 73 def initialize(env) @env = env @configuration = YAML.load_file(File.dirname(__FILE__)+"/../config/database.yml") @configuration['test']={} @configuration['development']={} @configuration['production'].each do |k,v| server = v.match(/^([^\/]*)/)[1] path = v.split("!!")[1] @configuration['test'][k] = "!!imbeh\\test\\#{server}\\#{path}" unless @configuration['test'][k] @configuration['development'][k] = "!!imbeh\\#{server}\\#{path}" unless @configuration['development'][k] end @db_view_cache = {} #{ :testdb => { nil => db, :key => view, }, ....} end |
Class Attribute Details
.session ⇒ Object (readonly)
Returns the value of attribute session.
7 8 9 |
# File 'lib/rdomino/session.rb', line 7 def session @session end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
87 88 89 |
# File 'lib/rdomino/session.rb', line 87 def configuration @configuration end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
87 88 89 |
# File 'lib/rdomino/session.rb', line 87 def env @env end |
Class Method Details
.addressbooks ⇒ Object
59 60 61 |
# File 'lib/rdomino/session.rb', line 59 def addressbooks @addressbooks ||= session.Addressbooks.map{|db| Database.new(nil,db) } end |
.get(env = ((defined? RAILS_ENV) ? RAILS_ENV.downcase : "test"), user = nil) ⇒ Object
This is the entrypoint to the library. Without a parameter it load the RAILS environment or the test environment
-
production,plog
-
development: !!imbeh/server/path
-
test: !!imbeh/test/server/path
Session.get ‘plog’
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rdomino/session.rb', line 16 def get(env = ((defined? RAILS_ENV) ? RAILS_ENV.downcase : "test"), user=nil ) @session ||= begin if env.kind_of? Symbol user = env env = "plog" end pw = prepare_notes_ini(user) print "opening domino session in #{env} environment..." s = WIN32OLE.new('Lotus.NotesSession') s.Initialize( pw ) puts "#{s.commonUserName} logged in" s end @singleton ||= new(env) end |
.locations ⇒ Object
67 68 69 |
# File 'lib/rdomino/session.rb', line 67 def locations private_addressbooks[0].open!['search:form="Location"'] end |
.prepare_notes_ini(user) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rdomino/session.rb', line 38 def prepare_notes_ini(user) authentification = YAML.load_file(File.dirname(__FILE__)+"/../config/auth.yml") unless user return (respond_to?(:mypw) ? mypw : ask('Domino password ?') { |q| q.echo = '*' } ) end authentification[:me][:pw] = mypw content = nil File.open( authentification[:notes_ini], 'r') { |f| content = f.readlines } File.open( authentification[:notes_ini], 'w') do |f| content.each do |line| key = line.split('=')[0] if authentification[user].keys.include?(key) f.write("#{key}=#{authentification[user][key]}\n") else f.write(line) end end end authentification[user][:pw] end |
.private_addressbooks ⇒ Object
63 64 65 |
# File 'lib/rdomino/session.rb', line 63 def private_addressbooks addressbooks.select{|db| db.Isprivateaddressbook } end |
.reload! ⇒ Object
32 33 34 35 36 |
# File 'lib/rdomino/session.rb', line 32 def reload! env = @singleton.env @singleton = @session = nil get(env) end |
Instance Method Details
#[](name, view = nil, key = nil) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rdomino/session.rb', line 92 def [](name, view=nil, key=nil) if value = @db_view_cache[name] db = value[nil] else db = Database.new(name,server_path(name)) value = @db_view_cache[name] = { nil => db} end unless cached = value[view] view_string = ( view.kind_of?(Symbol) ? @configuration[name][view] : view ) cached = db[ view_string ] @db_view_cache[name][view] = cached if view.kind_of?(Symbol) end ( key ? cached.get_document_by_key(key,true) : cached ) end |
#server_path(name) ⇒ Object
109 110 111 |
# File 'lib/rdomino/session.rb', line 109 def server_path(name) name.kind_of?(Symbol) ? @configuration[@env][name] : name end |