Class: Mongoose::IndexedColumn
- Inherits:
-
BaseColumn
- Object
- BaseColumn
- Mongoose::IndexedColumn
- Defined in:
- lib/mongoose/column.rb
Overview
IndexedColumn class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#idx ⇒ Object
readonly
Returns the value of attribute idx.
-
#index_file_name ⇒ Object
readonly
Returns the value of attribute index_file_name.
Attributes inherited from BaseColumn
#data_type, #name, #required, #tbl_class
Instance Method Summary collapse
-
#close ⇒ Object
—————————————————————————– close —————————————————————————–.
-
#index_file_out_of_date? ⇒ Boolean
—————————————————————————– index_file_out_of_date? —————————————————————————–.
-
#init_index ⇒ Object
—————————————————————————– init_index —————————————————————————–.
-
#initialize(tbl_class, name, col_def) ⇒ IndexedColumn
constructor
—————————————————————————– initialize —————————————————————————–.
-
#with_index_file(access = 'r') ⇒ Object
—————————————————————————– with_index_file —————————————————————————–.
Methods inherited from BaseColumn
create, #indexed?, #required?, valid_data_type?
Constructor Details
#initialize(tbl_class, name, col_def) ⇒ IndexedColumn
initialize
92 93 94 95 96 97 98 |
# File 'lib/mongoose/column.rb', line 92 def initialize(tbl_class, name, col_def) super @indexed = true @index_file_name = File.join(@tbl_class.db.path, @tbl_class.table_name.to_s + '_' + @name.to_s + TBL_IDX_EXT) end |
Instance Attribute Details
#idx ⇒ Object (readonly)
Returns the value of attribute idx.
87 88 89 |
# File 'lib/mongoose/column.rb', line 87 def idx @idx end |
#index_file_name ⇒ Object (readonly)
Returns the value of attribute index_file_name.
87 88 89 |
# File 'lib/mongoose/column.rb', line 87 def index_file_name @index_file_name end |
Instance Method Details
#close ⇒ Object
close
103 104 105 |
# File 'lib/mongoose/column.rb', line 103 def close rebuild_index_file if index_file_out_of_date? end |
#index_file_out_of_date? ⇒ Boolean
index_file_out_of_date?
132 133 134 135 136 137 138 139 140 |
# File 'lib/mongoose/column.rb', line 132 def index_file_out_of_date? if not File.exists?(@index_file_name) or (File.mtime(File.join( @tbl_class.db.path, @tbl_class.table_name.to_s + TBL_EXT)) > File.mtime(@index_file_name)) true else false end end |
#init_index ⇒ Object
init_index
110 111 112 113 114 115 116 |
# File 'lib/mongoose/column.rb', line 110 def init_index if File.exists?(@index_file_name) and not index_file_out_of_date? rebuild_index_from_index_file else rebuild_index_from_table end end |
#with_index_file(access = 'r') ⇒ Object
with_index_file
121 122 123 124 125 126 127 |
# File 'lib/mongoose/column.rb', line 121 def with_index_file(access='r') begin yield fptr = open(@index_file_name, access) ensure fptr.close end end |