Class: ActiveRecord::ConnectionAdapters::SpatiaLiteAdapter::SpatialColumn
- Inherits:
-
ConnectionAdapters::SQLiteColumn
- Object
- ConnectionAdapters::SQLiteColumn
- ActiveRecord::ConnectionAdapters::SpatiaLiteAdapter::SpatialColumn
- Defined in:
- lib/active_record/connection_adapters/spatialite_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.
-
#srid ⇒ Object
readonly
Returns the value of attribute srid.
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
- #set_srid(val_) ⇒ 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.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 53 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_) @srid = 0 if type == :spatial @limit = {:srid => @srid, :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.
75 76 77 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 75 def geometric_type @geometric_type end |
#srid ⇒ Object (readonly)
Returns the value of attribute srid.
74 75 76 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 74 def srid @srid end |
Instance Method Details
#klass ⇒ Object
83 84 85 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 83 def klass type == :spatial ? ::RGeo::Feature::Geometry : super end |
#set_srid(val_) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 66 def set_srid(val_) @srid = val_ if type == :spatial @limit[:srid] = @srid end end |
#spatial? ⇒ Boolean
78 79 80 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 78 def spatial? type == :spatial end |
#type_cast(value_) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 88 def type_cast(value_) if type == :spatial SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name, @srid) else super end end |
#type_cast_code(var_name_) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_column.rb', line 97 def type_cast_code(var_name_) if type == :spatial "::ActiveRecord::ConnectionAdapters::SpatiaLiteAdapter::SpatialColumn.convert_to_geometry("+ "#{var_name_}, ::ActiveRecord::ConnectionAdapters::SpatiaLiteAdapter::SpatialColumn::"+ "FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, "+ "#{name.inspect}, #{@srid})" else super end end |