conject 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,9 +38,10 @@ class Class
38
38
 
39
39
  # Define an internal reader method per dependency:
40
40
  syms.each do |object_name|
41
- mname = Conject::Utilities.generate_accessor_method_name(object_name)
42
- class_def_private mname do
43
- components[object_name]
41
+ Conject::Utilities.generate_accessor_method_names(object_name).each do |mname|
42
+ class_def_private mname do
43
+ components[object_name]
44
+ end
44
45
  end
45
46
  end
46
47
 
@@ -5,9 +5,10 @@ class Class
5
5
 
6
6
  # Define an internal reader method per dependency:
7
7
  syms.each do |object_name|
8
- mname = Conject::Utilities.generate_accessor_method_name(object_name)
9
- class_def_private mname do
10
- object_context[object_name]
8
+ Conject::Utilities.generate_accessor_method_names(object_name).each do |mname|
9
+ class_def_private mname do
10
+ object_context[object_name]
11
+ end
11
12
  end
12
13
  end
13
14
  end
@@ -6,8 +6,9 @@ module Conject
6
6
  init_arity == 0 or (RUBY_VERSION <= "1.9.2" and init_arity == -1)
7
7
  end
8
8
 
9
- def generate_accessor_method_name(object_name)
10
- object_name.to_s.split("/").last.to_sym
9
+ def generate_accessor_method_names(object_name)
10
+ parts = object_name.to_s.split("/").reject do |x| x == "" end
11
+ [ parts.join("_").to_sym, parts.last.to_sym ].uniq
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module Conject
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -21,6 +21,14 @@ describe "lazy dependency resolution via provide_with_objects" do
21
21
  baggins.to_s.should == "From the Shire, found the One Ring"
22
22
  end
23
23
 
24
+ it "includes both the convenient, short-hand object name in addition to the canonical" do
25
+ baggins = subject["hobbit/baggins"]
26
+ baggins.send(:shire).to_s.should == "Shire"
27
+ baggins.send(:hobbit_shire).to_s.should == "Shire"
28
+ baggins.send(:precious).to_s.should == "One Ring"
29
+ baggins.send(:hobbit_precious).to_s.should == "One Ring"
30
+ end
31
+
24
32
  it "can use deps inside #initialize" do
25
33
  gollum = subject["hobbit/smeagol"]
26
34
  gollum.saying.should == "They stole it from us, precious One Ring"
@@ -33,6 +33,20 @@ describe "module scoping" do
33
33
  obj.should_not be_nil
34
34
  obj.class.should == Chart::Presenter
35
35
 
36
+ model = obj.send(:chart_model)
37
+ model.should be
38
+ model.class.should == Chart::Model
39
+
40
+ view = obj.send(:chart_view)
41
+ view.should be
42
+ view.class.should == Chart::View
43
+ end
44
+
45
+ it "provides short (relative) object name accessors in addition to canonical accessors" do
46
+ obj = subject.get('chart/presenter')
47
+ obj.should_not be_nil
48
+ obj.class.should == Chart::Presenter
49
+
36
50
  model = obj.send(:model)
37
51
  model.should be
38
52
  model.class.should == Chart::Model
@@ -27,22 +27,22 @@ describe Conject::Utilities do
27
27
  end
28
28
  end
29
29
 
30
- describe ".generate_accessor_method_name" do
30
+ describe ".generate_accessor_method_names" do
31
31
  context "simple object names" do
32
32
  it "returns symbol names straight up" do
33
- subject.generate_accessor_method_name(:another_item).should == :another_item
33
+ subject.generate_accessor_method_names(:another_item).should == [:another_item]
34
34
  end
35
35
  it "converts strings to symbols" do
36
- subject.generate_accessor_method_name("the_object").should == :the_object
36
+ subject.generate_accessor_method_names("the_object").should == [:the_object]
37
37
  end
38
38
  end
39
39
 
40
40
  context "namespaced object names" do
41
41
  it "returns only the last step in the name" do
42
- subject.generate_accessor_method_name(:'one/two/three').should == :three
42
+ subject.generate_accessor_method_names(:'one/two/three').should == [:one_two_three, :three]
43
43
  end
44
44
  it "converts strings to symbols" do
45
- subject.generate_accessor_method_name("/aye/bee/cee").should == :cee
45
+ subject.generate_accessor_method_names("/aye/bee/cee").should == [:aye_bee_cee, :cee]
46
46
  end
47
47
  end
48
48
  end
@@ -5,5 +5,6 @@ module Hobbit
5
5
  def to_s
6
6
  "From the #{shire}, found the #{precious}"
7
7
  end
8
+
8
9
  end
9
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conject
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:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-19 00:00:00.000000000 Z
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  segments:
199
199
  - 0
200
- hash: -4433957660980631745
200
+ hash: 3653383717893701942
201
201
  required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  none: false
203
203
  requirements:
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  version: '0'
207
207
  segments:
208
208
  - 0
209
- hash: -4433957660980631745
209
+ hash: 3653383717893701942
210
210
  requirements: []
211
211
  rubyforge_project:
212
212
  rubygems_version: 1.8.24