-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic functionality for class injecting
- Loading branch information
kustosz
committed
Sep 9, 2014
1 parent
fd73a01
commit 2b22909
Showing
7 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Dependor | ||
module ClassTakesExt | ||
module_function | ||
def ClassTakes(*names) | ||
Module.new do | ||
define_singleton_method :extended do |klass| | ||
klass.send(:extend, Dependor::InjectableClass) | ||
klass.add_dependencies(*names) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Dependor | ||
module InjectableClass | ||
attr_accessor :class_takes | ||
def add_dependencies(*names) | ||
@class_takes = names | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Dependor | ||
class SubclassBuilder | ||
def self.subclass(klass, injector) | ||
return klass unless klass.respond_to?(:class_takes) | ||
|
||
Class.new(klass) do | ||
klass.class_takes.each do |dependency| | ||
define_singleton_method dependency do | ||
injector[dependency] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |