MixinCollection is a mechanism for adding arbitrary methods to geometry objects.
Normally, geometry objects respond to the methods defined in the feature interface for that type of geometry; e.g. RGeo::Feature::Geometry, RGeo::Feature::Point, etc. Some implementations include additional methods specific to the implementation. However, occasionally it is desirable also to include custom methods allowing objects to function in different contexts. To do so, provide those methods in a mixin Module, and add it to an appropriate MixinCollection. A MixinCollection is simply a collection of mixin Modules, connected to geometry types, that are included in objects of that type.
There is a global collection, MixinCollection::GLOBAL, which manages mixins to be added to all implementations. In addition, individual implementation factories may provide additional local MixinCollection objects for mixins specific to objects created by that factory.
Each mixin module added to a MixinCollection is connected to a specific type, which controls to which objects that mixin is added. For example, a mixin connected to Point is added only to Point objects. A mixin connected to GeometryCollection is added to GeometryCollection objects as well as MultiPoint, MultiLineString, and MultiPolygon, since those are subtypes of GeometryCollection. To add a mixin to all objects, connect it to the Geometry base type.
The global MixinCollection. Mixins added to this collection are added to all geometry objects for all implementations.
Create a new empty MixinCollection
# File lib/rgeo/feature/mixins.rb, line 140 def initialize @types = {} end
Add a module connected to the given type.
Shorthand for:
for_type(type_).add(module_)
# File lib/rgeo/feature/mixins.rb, line 160 def add(type_, module_) for_type(type_).add(module_) end
Returns a TypeData for the given type.
e.g. to add a module for point types, you can call:
for_type(::RGeo::Feature::Point).add(module)
# File lib/rgeo/feature/mixins.rb, line 150 def for_type(type_) (@types[type_] ||= TypeData.new(self, type_)) end
A class that implements this type should call this method to get the appropriate mixins.
Shorthand for:
for_type(type_).include_in_class(klass_, include_ancestry_)
# File lib/rgeo/feature/mixins.rb, line 171 def include_in_class(type_, klass_, include_ancestry_=false) for_type(type_).include_in_class(klass_, include_ancestry_) end
An object that implements this type should call this method to get the appropriate mixins.
Shorthand for:
for_type(type_).include_in_object(obj_, include_ancestry_)
# File lib/rgeo/feature/mixins.rb, line 182 def include_in_object(type_, obj_, include_ancestry_=false) for_type(type_).include_in_object(obj_, include_ancestry_) end