Class: IdZebra::Repository
- Inherits:
-
Struct
- Object
- Struct
- IdZebra::Repository
- Includes:
- Native
- Defined in:
- lib/idzebra.rb
Overview
Class representing a Zebra handle to a repository.
Operations are named to directly correspond to their counterparts in api.h and zebraidx, and so are not particularly Ruby-like.
Constant Summary
Constants included from Native
Instance Attribute Summary collapse
-
#zebra_handle ⇒ Object
Returns the value of attribute zebra_handle.
Instance Method Summary collapse
- #add_record(record_str) ⇒ Object
-
#clean ⇒ Object
(also: #rollback)
Rollback changes in shadow files and forget changes.
-
#commit ⇒ Object
Commit the shadow files.
-
#compact ⇒ Object
Attempt to save some space by compacting existing data files.
- #delete_record(record_str) ⇒ Object
- #get_resource(name, default = nil) ⇒ Object (also: #[])
-
#init ⇒ Object
Create a new repository (wiping any existing data).
- #set_resource(name, value) ⇒ Object (also: #[]=)
-
#transaction(read_only = false) ⇒ Object
Encapsulates the operation with ‘zebra_begin_trans` and `zebra_end_trans`.
- #update_record(record_str) ⇒ Object (also: #<<)
Instance Attribute Details
#zebra_handle ⇒ Object
Returns the value of attribute zebra_handle
136 137 138 |
# File 'lib/idzebra.rb', line 136 def zebra_handle @zebra_handle end |
Instance Method Details
#add_record(record_str) ⇒ Object
182 183 184 |
# File 'lib/idzebra.rb', line 182 def add_record(record_str) zebra_add_record(zebra_handle, record_str, 0) end |
#clean ⇒ Object Also known as: rollback
Rollback changes in shadow files and forget changes.
150 151 152 |
# File 'lib/idzebra.rb', line 150 def clean zebra_clean(zebra_handle) end |
#commit ⇒ Object
Commit the shadow files. Not designed to be run inside a transaction, but instead should be run after it.
156 157 158 159 160 161 |
# File 'lib/idzebra.rb', line 156 def commit transaction zebra_commit(zebra_handle) rescue TransactionError raise TransactionError, "Commit cannot occur inside a transaction." end |
#compact ⇒ Object
Attempt to save some space by compacting existing data files.
145 146 147 |
# File 'lib/idzebra.rb', line 145 def compact zebra_compact(zebra_handle) end |
#delete_record(record_str) ⇒ Object
191 192 193 194 |
# File 'lib/idzebra.rb', line 191 def delete_record(record_str) zebra_update_record(zebra_handle, :action_delete, nil, 0, nil, nil, record_str, 0) end |
#get_resource(name, default = nil) ⇒ Object Also known as: []
174 175 176 |
# File 'lib/idzebra.rb', line 174 def get_resource(name, default = nil) zebra_get_resource(zebra_handle, name, default) end |
#init ⇒ Object
Create a new repository (wiping any existing data).
140 141 142 |
# File 'lib/idzebra.rb', line 140 def init zebra_init(zebra_handle) end |
#set_resource(name, value) ⇒ Object Also known as: []=
178 179 180 |
# File 'lib/idzebra.rb', line 178 def set_resource(name, value) zebra_set_resource(zebra_handle, name, value) end |
#transaction(read_only = false) ⇒ Object
Encapsulates the operation with ‘zebra_begin_trans` and `zebra_end_trans`
164 165 166 167 168 169 170 171 172 |
# File 'lib/idzebra.rb', line 164 def transaction(read_only = false) zebra_res = zebra_begin_trans(zebra_handle, read_only ? 0 : 1) if zebra_res != 0 raise TransactionError, "Unable to start transaction - probably a locking issue." end yield if block_given? zebra_end_trans(zebra_handle) end |
#update_record(record_str) ⇒ Object Also known as: <<
186 187 188 189 |
# File 'lib/idzebra.rb', line 186 def update_record(record_str) zebra_update_record(zebra_handle, :action_update, nil, 0, nil, nil, record_str, 0) end |