Skip to content

Commit

Permalink
replaced ActiveSupport::InheritableAttributes with InheritableAttr (1…
Browse files Browse the repository at this point in the history
…3 lines, readable).
  • Loading branch information
apotonick committed Oct 2, 2010
1 parent a349973 commit 57dc90e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 2 additions & 4 deletions Rakefile
Expand Up @@ -13,8 +13,8 @@ Rake::TestTask.new(:test) do |test|
end

require 'jeweler'
$:.unshift File.dirname(__FILE__) # add current dir to LOAD_PATHS
require 'lib/hooks'
$:.unshift File.dirname(__FILE__)+"/lib" # add current dir to LOAD_PATHS
require 'hooks'

Jeweler::Tasks.new do |spec|
spec.name = "hooks"
Expand All @@ -26,8 +26,6 @@ Jeweler::Tasks.new do |spec|
spec.email = "apotonick@gmail.com"

spec.files = FileList["[A-Z]*", File.join(*%w[{lib} ** *]).to_s]

spec.add_dependency 'activesupport', '>= 2.3.0'
end

Jeweler::GemcutterTasks.new
7 changes: 5 additions & 2 deletions lib/hooks.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/class/inheritable_attributes.rb'
#require 'active_support/core_ext/class/inheritable_attributes.rb'
require "hooks/inheritable_attribute"

# Almost like ActiveSupport::Callbacks but 76,6% less complex.
#
Expand All @@ -19,6 +20,7 @@ module Hooks
VERSION = "0.1"

def self.included(base)
base.extend InheritableAttribute
base.extend ClassMethods
end

Expand Down Expand Up @@ -62,7 +64,8 @@ def #{hook}(method=nil, &block)
end

def setup_hook_accessors(accessor_name)
class_inheritable_array(accessor_name, :instance_writer => false)
#class_inheritable_array(accessor_name, :instance_writer => false)
inheritable_attr(accessor_name)
send("#{accessor_name}=", []) # initialize ivar.
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/hooks/inheritable_attribute.rb
Expand Up @@ -15,7 +15,8 @@ module InheritableAttribute
#
# and then, later
#
# Garfield.drinks #=> ["Becks, Fireman's 4"]
# Cat.drinks #=> ["Becks"]
# Garfield.drinks #=> ["Becks", "Fireman's 4"]
def inheritable_attr(name)
instance_eval %Q{
def #{name}=(v)
Expand Down
6 changes: 3 additions & 3 deletions test/hooks_test.rb
Expand Up @@ -33,10 +33,10 @@ def executed
end

should "be inherited" do
subklass = Class.new(@klass) do
end
@klass.after_eight :dine
subklass = Class.new(@klass)

assert_equal [], subklass.after_eight
assert_equal [:dine], subklass._after_eight_callbacks
end
end

Expand Down

0 comments on commit 57dc90e

Please sign in to comment.