Sha256: 3691a60027a7184d1d18b8a19ce2f070a0cb5dfdb8a78323864ce63432378a2e

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

module Spontaneous
  # Based on Concern but extended to allow running of
  # a 'before_include' block before the module is included and before the
  # 'included' block is run
  module Concern
    def self.extended(base)
      base.instance_variable_set("@_dependencies", [])
    end

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

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

    def before_include(&block)
      @_before_include_block = block
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta9 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta8 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta7 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta6 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta5 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta4 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta3 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta2 lib/spontaneous/concern.rb
spontaneous-0.2.0.beta1 lib/spontaneous/concern.rb