Class: ActiveDocument::Environment
- Inherits:
-
Object
- Object
- ActiveDocument::Environment
- Defined in:
- lib/active_document/environment.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #db ⇒ Object
-
#initialize(path) ⇒ Environment
constructor
A new instance of Environment.
- #open ⇒ Object
- #transaction ⇒ Object
Constructor Details
#initialize(path) ⇒ Environment
Returns a new instance of Environment.
2 3 4 |
# File 'lib/active_document/environment.rb', line 2 def initialize(path) @path = path end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/active_document/environment.rb', line 6 def env @env end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/active_document/environment.rb', line 6 def path @path end |
Instance Method Details
#close ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_document/environment.rb', line 26 def close if @env @env.close @env = nil end end |
#db ⇒ Object
8 9 10 |
# File 'lib/active_document/environment.rb', line 8 def db env.db end |
#open ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_document/environment.rb', line 12 def open if @env.nil? @env = Bdb::Env.new(0) env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist. Bdb::DB_INIT_TXN | # Initialize transactions Bdb::DB_INIT_LOCK | # Initialize locking. Bdb::DB_INIT_LOG | # Initialize logging Bdb::DB_INIT_MPOOL # Initialize the in-memory cache. @env.cachesize = 10 * 1024 * 1024 @env.flags_on = Bdb::DB_TXN_WRITE_NOSYNC @env.open(path, env_flags, 0) end end |
#transaction ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_document/environment.rb', line 33 def transaction if block_given? parent = @transaction @transaction = env.txn_begin(nil, 0) begin value = yield @transaction.commit(0) rescue Exception => e @transaction.abort raise e ensure @transaction = parent end value else @transaction end end |