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
#convert_to_native, create, #indexed?, #required?, valid_data_type?
Constructor Details
#initialize(tbl_class, name, col_def) ⇒ IndexedColumn
initialize
113 114 115 116 117 118 119 |
# File 'lib/mongoose/column.rb', line 113 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.
108 109 110 |
# File 'lib/mongoose/column.rb', line 108 def idx @idx end |
#index_file_name ⇒ Object (readonly)
Returns the value of attribute index_file_name.
108 109 110 |
# File 'lib/mongoose/column.rb', line 108 def index_file_name @index_file_name end |
Instance Method Details
#close ⇒ Object
close
124 125 126 |
# File 'lib/mongoose/column.rb', line 124 def close rebuild_index_file if index_file_out_of_date? end |
#index_file_out_of_date? ⇒ Boolean
index_file_out_of_date?
153 154 155 156 157 158 159 160 161 |
# File 'lib/mongoose/column.rb', line 153 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
131 132 133 134 135 136 137 |
# File 'lib/mongoose/column.rb', line 131 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
142 143 144 145 146 147 148 |
# File 'lib/mongoose/column.rb', line 142 def with_index_file(access='r') begin yield fptr = open(@index_file_name, access) ensure fptr.close end end |