objectify 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,10 +86,6 @@ module Objectify
86
86
  end
87
87
  end
88
88
 
89
- def resolvers
90
- @resolvers ||= NamedValueResolverLocator.new(NameTranslationResolver)
91
- end
92
-
93
89
  def instantiator
94
90
  @instantiator ||= Instantiator.new(injector)
95
91
  end
@@ -43,13 +43,8 @@ module Objectify
43
43
  end
44
44
 
45
45
  def objectify_route
46
- @objectify_route ||= if params[:objectify]
47
- Objectify::Route.new(params[:objectify][:resource].to_sym,
48
- params[:action].to_sym)
49
- else
50
- Objectify::Route.new(params[:controller].to_sym,
51
- params[:action].to_sym)
52
- end
46
+ resource_name = params[:objectify] ? params[:objectify][:resource] : params[:controller]
47
+ @objectify_route ||= Objectify::Route.new(resource_name.to_sym, params[:action].to_sym)
53
48
  end
54
49
 
55
50
  def action
@@ -14,11 +14,9 @@ module Objectify
14
14
  parameters = event.payload[:parameters].map do |req, param|
15
15
  param if req == :req
16
16
  end.compact
17
- resolvers = Hash[*parameters.zip(event.payload[:resolvers].map(&:class)).flatten]
18
17
  arguments = event.payload[:arguments].map(&:class).inspect[1..-2]
19
18
 
20
19
  message = " [Injector] Invoking #{object}.#{method}(#{arguments}). "
21
- message << "Resolutions: #{resolvers}. " if !resolvers.empty?
22
20
  message << duration(event)
23
21
 
24
22
  logger.debug(message)
@@ -1,3 +1,3 @@
1
1
  module Objectify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: objectify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70137374227200 !ruby/object:Gem::Requirement
16
+ requirement: &70203413321160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.4.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70137374227200
24
+ version_requirements: *70203413321160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &70137374226220 !ruby/object:Gem::Requirement
27
+ requirement: &70203413318700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70137374226220
35
+ version_requirements: *70203413318700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &70137374224820 !ruby/object:Gem::Requirement
38
+ requirement: &70203413317340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70137374224820
46
+ version_requirements: *70203413317340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bourne
49
- requirement: &70137374222400 !ruby/object:Gem::Requirement
49
+ requirement: &70203413316500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70137374222400
57
+ version_requirements: *70203413316500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: mocha
60
- requirement: &70137374221700 !ruby/object:Gem::Requirement
60
+ requirement: &70203419213280 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - =
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.8
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70137374221700
68
+ version_requirements: *70203419213280
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rails
71
- requirement: &70137378002540 !ruby/object:Gem::Requirement
71
+ requirement: &70203419212740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 3.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70137378002540
79
+ version_requirements: *70203419212740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: i18n
82
- requirement: &70137378000720 !ruby/object:Gem::Requirement
82
+ requirement: &70203419212340 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70137378000720
90
+ version_requirements: *70203419212340
91
91
  description: Objects on rails.
92
92
  email:
93
93
  - jamesgolick@gmail.com
@@ -111,7 +111,6 @@ files:
111
111
  - lib/objectify/injector.rb
112
112
  - lib/objectify/instantiator.rb
113
113
  - lib/objectify/instrumentation.rb
114
- - lib/objectify/logging.rb
115
114
  - lib/objectify/policy_chain_executor.rb
116
115
  - lib/objectify/rails/application.rb
117
116
  - lib/objectify/rails/controller.rb
@@ -120,8 +119,6 @@ files:
120
119
  - lib/objectify/rails/railtie.rb
121
120
  - lib/objectify/rails/renderer.rb
122
121
  - lib/objectify/rails/routing.rb
123
- - lib/objectify/resolver.rb
124
- - lib/objectify/resolver_locator.rb
125
122
  - lib/objectify/route.rb
126
123
  - lib/objectify/version.rb
127
124
  - objectify.gemspec
@@ -135,8 +132,6 @@ files:
135
132
  - spec/policy_chain_executor_spec.rb
136
133
  - spec/rails/renderer_spec.rb
137
134
  - spec/rails/routing_spec.rb
138
- - spec/resolver_locator_spec.rb
139
- - spec/resolver_spec.rb
140
135
  - spec/route_spec.rb
141
136
  - spec/spec_helper.rb
142
137
  - thoughts/injector.md
@@ -175,7 +170,5 @@ test_files:
175
170
  - spec/policy_chain_executor_spec.rb
176
171
  - spec/rails/renderer_spec.rb
177
172
  - spec/rails/routing_spec.rb
178
- - spec/resolver_locator_spec.rb
179
- - spec/resolver_spec.rb
180
173
  - spec/route_spec.rb
181
174
  - spec/spec_helper.rb
@@ -1,22 +0,0 @@
1
- require "logger"
2
-
3
- module Objectify
4
- module Logging
5
- class << self
6
- attr_writer :logger
7
-
8
- def logger
9
- @logger ||= Logger.new("/dev/null")
10
- end
11
- end
12
-
13
- private
14
- def logger
15
- if Kernel.const_defined?(:Rails)
16
- ::Rails.logger
17
- else
18
- Logging.logger
19
- end
20
- end
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- module Objectify
2
- class NamedValueResolver
3
- attr_reader :name
4
-
5
- def initialize(name, value)
6
- @name = name
7
- @value = value
8
- end
9
-
10
- def call
11
- @value
12
- end
13
- end
14
-
15
- class NameTranslationResolver
16
- attr_reader :name
17
-
18
- def initialize(name, value)
19
- @name = name
20
- @value = value.to_s.classify
21
- end
22
-
23
- def call
24
- @value.constantize.new
25
- end
26
- end
27
- end
@@ -1,73 +0,0 @@
1
- require "objectify/resolver"
2
-
3
- module Objectify
4
- class ArrayResolverLocator
5
- def initialize(resolvers)
6
- @resolvers = resolvers
7
- end
8
-
9
- def call(name)
10
- @resolvers.detect { |resolver| resolver.name == name }
11
- end
12
- end
13
-
14
- class MultiResolverLocator
15
- def initialize(locators)
16
- @locators = [*locators]
17
- end
18
-
19
- def call(name)
20
- @locators.each do |locator|
21
- resolver = locator.call(name)
22
- return resolver if resolver
23
- end
24
-
25
- raise ArgumentError, "No resolver found for #{name}."
26
- end
27
-
28
- def context(context)
29
- @locators.unshift(context)
30
- end
31
-
32
- def clear_context
33
- @locators.shift
34
- end
35
- end
36
-
37
- class NamedValueResolverLocator
38
- def initialize(resolver_factory = NamedValueResolver)
39
- @resolver_factory = resolver_factory
40
- @resolvers = {}
41
- end
42
-
43
- def add(name, value)
44
- @resolvers[name] = @resolver_factory.new(name, value)
45
- end
46
-
47
- def call(name)
48
- @resolvers[name]
49
- end
50
- end
51
-
52
- class ConstResolverLocator
53
- def initialize(namespace = nil)
54
- @namespace = namespace
55
- @cache = {}
56
- end
57
-
58
- def call(name)
59
- @cache[name] || locate_and_store(name)
60
- end
61
-
62
- private
63
- def locate_and_store(name)
64
- begin
65
- const_name = [@namespace, [name, :resolver].join("_")].compact.join("/")
66
- const_name.classify.constantize.new.tap do |obj|
67
- @cache[name] = obj
68
- end
69
- rescue NameError
70
- end
71
- end
72
- end
73
- end
@@ -1,109 +0,0 @@
1
- require "spec_helper"
2
- require "objectify/resolver_locator"
3
-
4
- describe "Objectify::ArrayResolverLocator" do
5
- before do
6
- @locator_a = stub("Resolver", :name => :a)
7
- @locator_b = stub("Resolver", :name => :b)
8
- @resolvers = [@locator_a, @locator_b]
9
- @resolver_locator = Objectify::ArrayResolverLocator.new(@resolvers)
10
- end
11
-
12
- it "returns locators by name" do
13
- @resolver_locator.call(:a).should == @locator_a
14
- @resolver_locator.call(:b).should == @locator_b
15
- end
16
- end
17
-
18
- describe "Objectify::MultiResolverLocator" do
19
- before do
20
- @locator_a = stub("LocatorA", :call => nil)
21
- @locator_a.stubs(:call).with(:a).returns(:resolver_a)
22
- @locator_b = stub("LocatorB", :call => nil)
23
- @locator_b.stubs(:call).with(:b).returns(:resolver_b)
24
-
25
- @locators = [@locator_a, @locator_b]
26
- @resolver_locator = Objectify::MultiResolverLocator.new(@locators)
27
- end
28
-
29
- it "searches through its locators for a resolver" do
30
- @resolver_locator.call(:a).should == :resolver_a
31
- @resolver_locator.call(:b).should == :resolver_b
32
- end
33
-
34
- it "raises ArgumentError when a resolver can't be found" do
35
- not_found = lambda { @resolver_locator.call(:asdf) }
36
- not_found.should raise_error(ArgumentError)
37
- end
38
-
39
- it "accepts a temporary, contextual locator which takes priority" do
40
- @temp_locator = stub("TempLocator", :call => :temp_resolver)
41
- @resolver_locator.context(@temp_locator)
42
- @resolver_locator.call(:a).should == :temp_resolver
43
- @resolver_locator.clear_context
44
- @resolver_locator.call(:a).should == :resolver_a
45
- end
46
- end
47
-
48
- describe "Objectify::NamedValueResolverLocator" do
49
- before do
50
- @resolver = stub("Resolver")
51
- @factory = stub("ResolverFactory", :new => @resolver)
52
- @locator = Objectify::NamedValueResolverLocator.new(@factory)
53
- end
54
-
55
- it "#call returns the per-name resolver" do
56
- @locator.add(:name, :value)
57
- @locator.call(:name).should == @resolver
58
- end
59
-
60
- it "#add creates a resolver for the supplied key/value pair" do
61
- @locator.add(:name, :value)
62
- @factory.should have_received(:new).with(:name, :value)
63
- end
64
- end
65
-
66
- class MyResolver; end
67
- module Something; class MyResolver; end; end
68
-
69
- describe "Objectify::ConstResolverLocator" do
70
- context "in the global namespace" do
71
- before do
72
- @locator = Objectify::ConstResolverLocator.new
73
- end
74
-
75
- it "finds resolvers by const name" do
76
- @locator.call(:my).should be_instance_of(MyResolver)
77
- end
78
-
79
- it "returns nil if the const is missing" do
80
- @locator.call(:missing).should be_nil
81
- end
82
-
83
- it "keeps a cache of instantiated resolvers" do
84
- obj1 = @locator.call(:my)
85
- obj2 = @locator.call(:my)
86
- obj1.object_id.should == obj2.object_id
87
- end
88
- end
89
-
90
- context "in an arbitrary namespace" do
91
- before do
92
- @locator = Objectify::ConstResolverLocator.new("something")
93
- end
94
-
95
- it "finds resolvers by const name" do
96
- @locator.call(:my).should be_instance_of(Something::MyResolver)
97
- end
98
-
99
- it "returns nil if the const is missing" do
100
- @locator.call(:missing).should be_nil
101
- end
102
-
103
- it "keeps a cache of instantiated resolvers" do
104
- obj1 = @locator.call(:my)
105
- obj2 = @locator.call(:my)
106
- obj1.object_id.should == obj2.object_id
107
- end
108
- end
109
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
- require "objectify/resolver"
3
-
4
- describe "Objectify::NamedValueResolver" do
5
- before do
6
- @named_value_resolver = Objectify::NamedValueResolver.new(:name, :value)
7
- end
8
-
9
- it "returns the supplied name" do
10
- @named_value_resolver.name.should == :name
11
- end
12
-
13
- it "returns the supplied value" do
14
- @named_value_resolver.call.should == :value
15
- end
16
- end
17
-
18
- class MyResolver; end
19
-
20
- describe "Objectify::NameTranslationResolver" do
21
- before do
22
- @resolver = Objectify::NameTranslationResolver.new(:a, :my_resolver)
23
- end
24
-
25
- it "instantiates resolvers" do
26
- @resolver.call.should be_instance_of(MyResolver)
27
- end
28
- end