Module: Trax::Core::HasMixins

Defined in:
lib/trax/core/has_mixins.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/trax/core/has_mixins.rb', line 13

def self.extended(base)
  base.module_attribute(:mixin_registry) { Hash.new }
  base.extend(ClassMethods)

  base.define_configuration_options! do
    option :auto_include, :default => false
    option :auto_include_mixins, :default => []
  end

  mixin_module = base.const_set("Mixin", ::Module.new)
  mixin_module.module_attribute(:mixin_namespace) { base }

  # NOTE: This line causes specs to fail, because it loads before
  # ::Trax::Core::Definitions. It's currently not being used by any other
  # Trax gems, so we'll have to revisit this whenever they start using it
  #mixin_module.extend(::Trax::Core::Mixin)

  mixin_module.module_eval do
    def self.extended(base)
      base.extend(Trax::Core::Mixin)
      super(base)
      mixin_namespace.register_mixin(base)
    end
  end

  mixable_module = base.const_set("Mixable", ::Module.new)
  mixable_module.module_attribute(:mixin_namespace) { base }
  mixable_module.extend(::ActiveSupport::Concern)

  mixable_module.included do
    class_attribute :mixin_namespace
    self.mixin_namespace = base
  end

  mixable_module.include(::Trax::Core::Mixable)

  super(base)
end