Class: Mongoose::IndexedColumn

Inherits:
BaseColumn show all
Defined in:
lib/mongoose/column.rb

Overview


IndexedColumn class


Direct Known Subclasses

IDColumn, SkipListIndexColumn

Instance Attribute Summary collapse

Attributes inherited from BaseColumn

#data_type, #name, #required, #tbl_class

Instance Method Summary collapse

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

#idxObject (readonly)

Returns the value of attribute idx.



87
88
89
# File 'lib/mongoose/column.rb', line 87

def idx
  @idx
end

#index_file_nameObject (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

#closeObject


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?


Returns:

  • (Boolean)


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_indexObject


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