Skip to content

Commit

Permalink
add decorators to Config::Injectables
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed May 29, 2012
1 parent 83273db commit 92cbaf6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/objectify/config/injectables.rb
Expand Up @@ -6,6 +6,7 @@ class Injectables

def initialize(config = {})
@config = config
@decorators = {}
end

def add_resolver(name, value)
Expand All @@ -24,6 +25,14 @@ def get(name)
@config[name] || context[name] || [:unknown, name]
end

def add_decorators(name, value)
@decorators[name] = value
end

def decorators(name)
[*@decorators[name]].compact
end

def context
@context && @context.config || {}
end
Expand Down
8 changes: 8 additions & 0 deletions spec/config/injectables_spec.rb
Expand Up @@ -37,4 +37,12 @@
@injectables.context = @context
@injectables.get(:controller).should == [:value, :something]
end

it "accepts decorators" do
@injectables.add_decorators(:base, :decorator1)
@injectables.decorators(:base).should == [:decorator1]
@injectables.add_decorators(:base, [:decorator1, :decorator2])
@injectables.decorators(:base).should == [:decorator1, :decorator2]
@injectables.decorators(:nonexistent).should == []
end
end

0 comments on commit 92cbaf6

Please sign in to comment.