<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -4,19 +4,28 @@ module Ono
     def initialize(path)
       @path = File.expand_path path
       @files = {}
+      @targets = {}
     end
 
     def file(rel_path)
-      if @files[rel_path]
+      return @files[rel_path] if @files[rel_path]
+      file = RepoFile.new(rel_path, self)
+      if file.exists?
+        @files[rel_path] = file
         return @files[rel_path]
       else
-        file = RepoFile.new(rel_path, self)
-        if file.exists?
-          @files[rel_path] = file
-          return @files[rel_path]
-        else
-          return nil
-        end
+        return nil
+      end
+    end
+
+    def target(name)
+      return @targets[name] if @targets[name]
+      target = Target.new(name, self)
+      if target.valid?
+        @targets[name] = target
+        return target
+      else
+        return nil
       end
     end
 
@@ -42,6 +51,10 @@ module Ono
       @src = find_src
     end
 
+    def valid?
+      return @src != nil
+    end
+
     private
     def find_src
       extensions = [&quot;.c&quot;, &quot;.cc&quot;, &quot;.cpp&quot;, &quot;.c++&quot;, &quot;.cxx&quot;, &quot;.C&quot;]</diff>
      <filename>lib/ono/model.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,11 +18,10 @@ module Ono
         assert_equal Dir.pwd, @repo.path
       end
 
-      context &quot;when #file(..) is called&quot; do
+      context &quot;when #file(FILE) is called&quot; do
         setup do
           @repo = Repository.new(File.join(TEST_DATA_DIR, &quot;ws1&quot;))
         end
-
         should &quot;return a RepoFile if the file exists&quot; do
           assert @repo.file(&quot;test.cc&quot;)
           assert_equal &quot;test.cc&quot;, @repo.file(&quot;test.cc&quot;).path
@@ -32,6 +31,22 @@ module Ono
           assert_nil @repo.file(&quot;missing.cc&quot;)
         end
       end
+
+      context &quot;when #target(TARGET) is called&quot; do
+        setup do
+          @repo = Repository.new(File.join(TEST_DATA_DIR, &quot;ws1&quot;))
+        end
+        context &quot;if TARGET is valid&quot; do
+          setup do
+            @target = @repo.target(&quot;test.o&quot;)
+          end
+
+          should &quot;return a Target object of the target&quot; do
+            assert_not_nil @target
+            assert_equal &quot;test.o&quot;, @target.name
+          end
+        end
+      end
     end
 
     context &quot;A target&quot; do
@@ -39,6 +54,16 @@ module Ono
         @repo = Repository.new(File.join(TEST_DATA_DIR, &quot;ws1&quot;))
       end
 
+      context &quot;when it doesn't have corresponding source&quot; do
+        setup do
+          @target = Target.new(&quot;missing.o&quot;, @repo)
+        end
+
+        should &quot;be invalid&quot; do
+          assert !@target.valid?
+        end
+      end
+
       context &quot;when it's an object and the corresponding source exists&quot; do
         setup do
           @target = Target.new(&quot;test.o&quot;, @repo)</diff>
      <filename>test/test_model.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d9cd173d0f7d735a22319acb3a25087e2d55593e</id>
    </parent>
  </parents>
  <author>
    <name>Hong Jiang</name>
    <email>hong@hjiang.net</email>
  </author>
  <url>http://github.com/hjiang/ono/commit/4f88c6e6779fc45171b076a2b8be873d0c69c92c</url>
  <id>4f88c6e6779fc45171b076a2b8be873d0c69c92c</id>
  <committed-date>2009-10-18T00:18:52-07:00</committed-date>
  <authored-date>2009-10-18T00:18:52-07:00</authored-date>
  <message>added Repository#target and test</message>
  <tree>1a7bd58d278487a5f5281a0a64a5ae9f9a6bdf7e</tree>
  <committer>
    <name>Hong Jiang</name>
    <email>hong@hjiang.net</email>
  </committer>
</commit>
