Class: ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb

Constant Summary collapse

FACTORY_SETTINGS_CACHE =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(factory_settings_, table_name_, name_, default_, sql_type_ = nil, null_ = true) ⇒ SpatialColumn

Returns a new instance of SpatialColumn.



48
49
50
51
52
53
54
55
56
57
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 48

def initialize(factory_settings_, table_name_, name_, default_, sql_type_=nil, null_=true)
  @factory_settings = factory_settings_
  @table_name = table_name_
  super(name_, default_,sql_type_, null_)
  @geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(sql_type_)
  if type == :spatial
    @limit = { type: @geometric_type.type_name.underscore }
  end
  FACTORY_SETTINGS_CACHE[factory_settings_.object_id] = factory_settings_
end

Instance Attribute Details

#geometric_typeObject (readonly)

Returns the value of attribute geometric_type.



59
60
61
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 59

def geometric_type
  @geometric_type
end

Instance Method Details

#klassObject



65
66
67
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 65

def klass
  type == :spatial ? ::RGeo::Feature::Geometry : super
end

#spatial?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 61

def spatial?
  type == :spatial
end

#type_cast(value_) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 69

def type_cast(value_)
  if type == :spatial
    SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name)
  else
    super
  end
end

#type_cast_code(var_name_) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/active_record/connection_adapters/mysql2spatial_adapter/spatial_column.rb', line 77

def type_cast_code(var_name_)
  if type == :spatial
    "::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn.convert_to_geometry("+
      "#{var_name_}, ::ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter::SpatialColumn::"+
      "FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, #{name.inspect})"
  else
    super
  end
end