# File lib/thinking_sphinx/active_record/attribute/type.rb, line 4 def initialize(attribute, model) @attribute, @model = attribute, model end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 8 def multi? @multi ||= attribute.options[:multi] || multi_from_associations end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 12 def timestamp? type == :timestamp end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 16 def type @type ||= attribute.options[:type] || type_from_database end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 20 def type=(value) @type = attribute.options[:type] = value end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 24 def updateable? UPDATEABLE_TYPES.include?(type) && single_column_reference? end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 32 def associations @associations ||= begin klass = model attribute.columns.first.__stack.collect { |name| association = klass.reflect_on_association(name) klass = association.klass association } end end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 43 def klass @klass ||= associations.any? ? associations.last.klass : model end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 47 def multi_from_associations associations.any? { |association| [:has_many, :has_and_belongs_to_many].include?(association.macro) } end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 53 def single_column_reference? attribute.columns.length == 1 && attribute.columns.first.__stack.length == 0 && !attribute.columns.first.string? end
# File lib/thinking_sphinx/active_record/attribute/type.rb, line 59 def type_from_database db_column = klass.columns.detect { |db_column| db_column.name == attribute.columns.first.__name.to_s } if db_column.type == :integer && db_column.sql_type[/bigint/] return :bigint end case db_column.type when :datetime, :date :timestamp when :text :string when :decimal :float else db_column.type end end