Class: RGeo::Feature::MixinCollection::TypeData

Inherits:
Object
  • Object
show all
Defined in:
lib/rgeo/feature/mixins.rb

Overview

An API point controlling a particular type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection_, type_) ⇒ TypeData

:nodoc:


78
79
80
81
82
83
84
85
# File 'lib/rgeo/feature/mixins.rb', line 78

def initialize(collection_, type_)  # :nodoc:
  @collection = collection_
  @type = type_
  @mixins = []
  @classes = []
  @rmixins = []
  @rclasses = []
end

Instance Attribute Details

#collectionObject (readonly)

The MixinCollection owning this data


92
93
94
# File 'lib/rgeo/feature/mixins.rb', line 92

def collection
  @collection
end

#typeObject (readonly)

The feature type


89
90
91
# File 'lib/rgeo/feature/mixins.rb', line 89

def type
  @type
end

Instance Method Details

#_radd(module_) ⇒ Object

:nodoc:


127
128
129
130
131
132
# File 'lib/rgeo/feature/mixins.rb', line 127

def _radd(module_)  # :nodoc:
  @rmixins << module_
  @rclasses.each{ |k_| k_.class_eval{ include(module_) } }
  @type.each_immediate_subtype{ |t_| @collection.for_type(t_)._radd(module_) }
  self
end

#add(module_) ⇒ Object

Add a mixin to be included in implementations of this type.


97
98
99
100
101
# File 'lib/rgeo/feature/mixins.rb', line 97

def add(module_)
  @mixins << module_
  @classes.each{ |k_| k_.class_eval{ include(module_) } }
  _radd(module_)
end

#include_in_class(klass_, include_ancestry_ = false) ⇒ Object

A class that implements this type should call this method to get the appropriate mixins. If include_ancestry_ is set to true, then mixins connected to subtypes of this type are also added to the class.


109
110
111
112
113
# File 'lib/rgeo/feature/mixins.rb', line 109

def include_in_class(klass_, include_ancestry_=false)
  (include_ancestry_ ? @rmixins : @mixins).each{ |m_| klass_.class_eval{ include(m_) } }
  (include_ancestry_ ? @rclasses : @classes) << klass_
  self
end

#include_in_object(obj_, include_ancestry_ = false) ⇒ Object

An object that implements this type should call this method to get the appropriate mixins. If include_ancestry_ is set to true, then mixins connected to subtypes of this type are also added to the object.


121
122
123
124
# File 'lib/rgeo/feature/mixins.rb', line 121

def include_in_object(obj_, include_ancestry_=false)
  (include_ancestry_ ? @rmixins : @mixins).each{ |m_| obj_.extend(m_) }
  self
end