Module: Sprout::Concern
- Included in:
- Base, Daemon, Executable, RubyFeature
- Defined in:
- lib/sprout/concern.rb
Overview
This class was copied from Rails source code and provides our RubyFeature with the ability to more clearly mix in functionality against a class and behave as if inheritance works at the class mixin level.
TODO: I'd like to update our system so that this functionality is no longer necessary - if you have ideas or opinions about this code, please let me know!
Class Method Summary (collapse)
-
+ (Object) extended(base)
Callback handler when a class is extended.
Instance Method Summary (collapse)
-
- (Object) append_features(base)
Apply both class and instance features found in the base class to the new subclass.
-
- (Object) included(base = nil, &block)
Handle inclusion of this module.
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
26 27 28 |
# File 'lib/sprout/concern.rb', line 26 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.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sprout/concern.rb', line 33 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.
49 50 51 52 53 54 55 |
# File 'lib/sprout/concern.rb', line 49 def included(base = nil, &block) if base.nil? @_included_block = block else super end end |