Module: RGeo::ActiveRecord::ActiveRecordBaseFactorySettings
- Defined in:
- lib/rgeo/active_record/ar_factory_settings.rb
Overview
Additional class methods on ::ActiveRecord::Base that provide a way to control the RGeo factory used for ActiveRecord objects.
Instance Method Summary collapse
-
#rgeo_factory_for_column(column_name_, params_ = nil) ⇒ Object
Returns the factory generator or specific factory to use for this ActiveRecord class and the given column name.
-
#rgeo_factory_generator ⇒ Object
The value of this attribute is a RGeo::Feature::FactoryGenerator that is used to generate the proper factory when loading geometry objects from the database.
-
#rgeo_factory_generator=(gen_) ⇒ Object
Set the rgeo_factory_generator attribute.
-
#rgeo_factory_settings ⇒ Object
Return the RGeoFactorySettings object associated with this class’s connection.
-
#set_rgeo_factory_for_column(column_name_, factory_) ⇒ Object
Set a specific factory for this ActiveRecord class and the given column name.
-
#to_generate_rgeo_factory(&block_) ⇒ Object
This is a convenient way to set the rgeo_factory_generator by passing a block.
Instance Method Details
#rgeo_factory_for_column(column_name_, params_ = nil) ⇒ Object
Returns the factory generator or specific factory to use for this ActiveRecord class and the given column name. If an explicit factory was set for the given column, returns it. Otherwise, if a params hash is given, passes that hash to the rgeo_factory_generator for this class, and returns the resulting factory. Otherwise, if no params hash is given, just returns the rgeo_factory_generator for this class.
119 120 121 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 119 def rgeo_factory_for_column(column_name_, params_=nil) rgeo_factory_settings.get_column_factory(table_name, column_name_, params_) end |
#rgeo_factory_generator ⇒ Object
The value of this attribute is a RGeo::Feature::FactoryGenerator that is used to generate the proper factory when loading geometry objects from the database. For example, if the data being loaded has M but not Z coordinates, and an embedded SRID, then this FactoryGenerator is called with the appropriate configuration to obtain a factory with those properties. This factory is the one associated with the actual geometry properties of the ActiveRecord object. The result of this generator can be overridden by setting an explicit factory for a given class and column using the column_rgeo_factory method.
90 91 92 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 90 def rgeo_factory_generator rgeo_factory_settings.get_factory_generator(table_name) end |
#rgeo_factory_generator=(gen_) ⇒ Object
Set the rgeo_factory_generator attribute
95 96 97 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 95 def rgeo_factory_generator=(gen_) rgeo_factory_settings.set_factory_generator(table_name, gen_) end |
#rgeo_factory_settings ⇒ Object
Return the RGeoFactorySettings object associated with this class’s connection.
70 71 72 73 74 75 76 77 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 70 def rgeo_factory_settings pool_ = begin connection_pool rescue ::ActiveRecord::ConnectionNotEstablished nil end pool_ ? pool_.rgeo_factory_settings : RGeoFactorySettings::DEFAULT end |
#set_rgeo_factory_for_column(column_name_, factory_) ⇒ Object
Set a specific factory for this ActiveRecord class and the given column name. This setting, if present, overrides the result of the rgeo_factory_generator.
108 109 110 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 108 def set_rgeo_factory_for_column(column_name_, factory_) rgeo_factory_settings.set_column_factory(table_name, column_name_, factory_) end |
#to_generate_rgeo_factory(&block_) ⇒ Object
This is a convenient way to set the rgeo_factory_generator by passing a block.
101 102 103 |
# File 'lib/rgeo/active_record/ar_factory_settings.rb', line 101 def to_generate_rgeo_factory(&block_) rgeo_factory_settings.set_factory_generator(table_name, block_) end |