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:



41
42
43
44
45
46
47
48
# File 'lib/rgeo/feature/mixins.rb', line 41

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

Instance Attribute Details

#collectionObject (readonly)

The MixinCollection owning this data



54
55
56
# File 'lib/rgeo/feature/mixins.rb', line 54

def collection
  @collection
end

#typeObject (readonly)

The feature type



51
52
53
# File 'lib/rgeo/feature/mixins.rb', line 51

def type
  @type
end

Instance Method Details

#_radd(module_) ⇒ Object

:nodoc:



85
86
87
88
89
90
# File 'lib/rgeo/feature/mixins.rb', line 85

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.



58
59
60
61
62
# File 'lib/rgeo/feature/mixins.rb', line 58

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.



69
70
71
72
73
# File 'lib/rgeo/feature/mixins.rb', line 69

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.



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

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