Skip to content

Instantly share code, notes, and snippets.

@NZKoz
Created July 29, 2010 00:55
Show Gist options
  • Select an option

  • Save NZKoz/496901 to your computer and use it in GitHub Desktop.

Select an option

Save NZKoz/496901 to your computer and use it in GitHub Desktop.
# Back Port of ActiveSupport::Concern
# Copyright (c) 2005-2010 David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module HacktiveSupport
module DependencyModule
def append_features(base)
return false if base < self
(@_dependencies ||= []).each { |dep| base.send(:include, dep) }
super
end
def depends_on(*mods)
mods.each do |mod|
next if self < mod
@_dependencies ||= []
@_dependencies << mod
end
end
end
module Concern
include DependencyModule
def append_features(base)
if 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
def included(base = nil, &block)
if base.nil?
@_included_block = block
else
super
end
end
alias_method :include, :depends_on
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment