diff --git a/.gitignore b/.gitignore index 20db3fc..a22ff2f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .config .rvmrc .yardoc +.ruby-* Gemfile.lock coverage pkg/* diff --git a/lib/protobuf/active_record/columns.rb b/lib/protobuf/active_record/columns.rb index 7b65b23..3d9f49d 100644 --- a/lib/protobuf/active_record/columns.rb +++ b/lib/protobuf/active_record/columns.rb @@ -39,20 +39,22 @@ def _protobuf_datetime_column?(key) # Map out the columns for future reference on type conversion # :nodoc: def _protobuf_map_columns(force = false) - return unless table_exists? + ::Thread.exclusive do + @_protobuf_mapped_columns = false if force - @_protobuf_mapped_columns = false if force - return if _protobuf_mapped_columns? + return unless table_exists? + return if _protobuf_mapped_columns? - @_protobuf_columns = {} - @_protobuf_column_types = Hash.new { |h,k| h[k] = [] } + @_protobuf_columns = {} + @_protobuf_column_types = Hash.new { |h,k| h[k] = [] } - columns.map do |column| - @_protobuf_columns[column.name.to_sym] = column - @_protobuf_column_types[column.type.to_sym] << column.name.to_sym - end + columns.map do |column| + @_protobuf_columns[column.name.to_sym] = column + @_protobuf_column_types[column.type.to_sym] << column.name.to_sym + end - @_protobuf_mapped_columns = true + @_protobuf_mapped_columns = true + end end def _protobuf_mapped_columns?