Class: ActiveRecord::ConnectionAdapters::MysqlSpatialAdapter::SpatialColumn
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::MysqlSpatialAdapter::SpatialColumn
- Defined in:
- lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb
Constant Summary collapse
- FACTORY_SETTINGS_CACHE =
{}
Instance Attribute Summary collapse
-
#geometric_type ⇒ Object
readonly
Returns the value of attribute geometric_type.
Instance Method Summary collapse
-
#initialize(factory_settings_, table_name_, name_, default_, sql_type_ = nil, null_ = true) ⇒ SpatialColumn
constructor
A new instance of SpatialColumn.
- #klass ⇒ Object
- #spatial? ⇒ Boolean
- #type_cast(value_) ⇒ Object
- #type_cast_code(var_name_) ⇒ Object
Constructor Details
#initialize(factory_settings_, table_name_, name_, default_, sql_type_ = nil, null_ = true) ⇒ SpatialColumn
Returns a new instance of SpatialColumn.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 57 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_type ⇒ Object (readonly)
Returns the value of attribute geometric_type.
69 70 71 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 69 def geometric_type @geometric_type end |
Instance Method Details
#klass ⇒ Object
77 78 79 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 77 def klass type == :spatial ? ::RGeo::Feature::Geometry : super end |
#spatial? ⇒ Boolean
72 73 74 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 72 def spatial? type == :spatial end |
#type_cast(value_) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 82 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
91 92 93 94 95 96 97 98 99 |
# File 'lib/active_record/connection_adapters/mysqlspatial_adapter/spatial_column.rb', line 91 def type_cast_code(var_name_) if type == :spatial "::ActiveRecord::ConnectionAdapters::MysqlSpatialAdapter::SpatialColumn.convert_to_geometry("+ "#{var_name_}, ::ActiveRecord::ConnectionAdapters::MysqlSpatialAdapter::SpatialColumn::"+ "FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, #{name.inspect})" else super end end |