Module: Sprout::Concern

Included in:
RubyFeature
Defined in:
sprout/lib/sprout/concern.rb

Overview

This class was copied from Rails source code and enhances Ruby's native mixin functionality for our Sprout::RubyFeature.

I'd like to work to get rid of this class, and the confusion that it introduces.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) extended(base)

Callback handler when a class is extended. This handler will set the @_dependencies array on the concrete class that just extended a 'Concern'.

This callback is often triggered with:

class Foo
  extend Concern
end


24
25
26
# File 'sprout/lib/sprout/concern.rb', line 24

def self.extended(base)
  base.instance_variable_set("@_dependencies", [])
end

Instance Method Details

- (Object) append_features(base)

Apply both class and instance features found in the base class to the new subclass.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'sprout/lib/sprout/concern.rb', line 31

def append_features(base)
  if base.instance_variable_defined?("@_dependencies")
    base.instance_variable_get("@_dependencies") << self
    return false
  else
    return false if base < self
    @_dependencies.each { |dep| base.send(:include, dep) }
    super
    base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
    base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
    base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
  end
end

- (Object) included(base = nil, &block)

Handle inclusion of this module.



47
48
49
50
51
52
53
# File 'sprout/lib/sprout/concern.rb', line 47

def included(base = nil, &block)
  if base.nil?
    @_included_block = block
  else
    super
  end
end