Skip to content
This repository
Browse code

simplify blueprint loading

  • Loading branch information...
commit 2a8357f4d21fd88b7f8ef4aef45e879e3817c580 1 parent 8b40670
Ryan Carver authored
8  lib/config/blueprint.rb
@@ -2,13 +2,7 @@ module Config
2 2
   class Blueprint
3 3
     include Config::Core::Loggable
4 4
 
5  
-    def self.from_file(path)
6  
-      name = File.basename(path, ".rb")
7  
-      content = File.read(path)
8  
-      from_string(name, content, path.to_s, 1)
9  
-    end
10  
-
11  
-    def self.from_string(name, string, _file=nil, _line=nil)
  5
+    def self.from_string(name, string, _file, _line = 1)
12 6
       new(name) do
13 7
         if _file && _line
14 8
           eval string, binding, _file, _line
9  lib/config/project_loader.rb
@@ -89,8 +89,13 @@ def require_clusters
89 89
     def require_blueprints
90 90
       return if @required_blueprints; @required_blueprints = true
91 91
 
92  
-      Dir[(@path + "blueprints/*.rb")].each do |f|
93  
-        blueprint = Blueprint.from_file(f)
  92
+      Dir[(@path + "blueprints/*.rb")].each do |path|
  93
+        file = Config::Core::File.new(path)
  94
+        blueprint = Blueprint.from_string(
  95
+          file.basename,
  96
+          file.read,
  97
+          file.path
  98
+        )
94 99
         @blueprints[blueprint.name] = blueprint
95 100
       end
96 101
     end
37  test/integration/blueprint_eval_test.rb
@@ -5,7 +5,7 @@
5 5
   describe ".from_string" do
6 6
 
7 7
     it "works" do
8  
-      blueprint = Config::Blueprint.from_string("sample", <<-STR)
  8
+      blueprint = Config::Blueprint.from_string("sample", <<-STR, __FILE__)
9 9
         file "/tmp/file"
10 10
       STR
11 11
       blueprint.to_s.must_equal "Blueprint sample"
@@ -16,7 +16,7 @@
16 16
     it "provides useful information for a syntax error" do
17 17
       file = __FILE__
18 18
       line = __LINE__ + 2
19  
-      blueprint = Config::Blueprint.from_string("sample", <<-STR, __FILE__, __LINE__)
  19
+      blueprint = Config::Blueprint.from_string("sample", <<-STR, file, line)
20 20
         file "/tmp/file"
21 21
         xfile "/tmp/other"
22 22
       STR
@@ -30,36 +30,3 @@
30 30
     end
31 31
   end
32 32
 end
33  
-
34  
-describe "filesystem", Config::Blueprint do
35  
-
36  
-  describe ".from_file" do
37  
-
38  
-    let(:file) { tmpdir + "sample.rb" }
39  
-
40  
-    it "works" do
41  
-      file.open("w") do |f|
42  
-        f.puts %(file "/tmp/file")
43  
-      end
44  
-      blueprint = Config::Blueprint.from_file(file)
45  
-      blueprint.to_s.must_equal "Blueprint sample"
46  
-      accumulation = blueprint.accumulate
47  
-      accumulation.size.must_equal 1
48  
-    end
49  
-
50  
-    it "provides useful information for an error" do
51  
-      file.open("w") do |f|
52  
-        f.puts %(file "/tmp/file")
53  
-        f.puts %(xfile "/tmp/other")
54  
-      end
55  
-      blueprint = Config::Blueprint.from_file(file)
56  
-      begin
57  
-        blueprint.accumulate
58  
-      rescue => e
59  
-        e.class.must_equal NoMethodError
60  
-        e.message.must_equal %(undefined method `xfile' for <Blueprint>:Config::DSL::BlueprintDSL)
61  
-        e.backtrace.first.must_equal "#{file}:2:in `block in from_string'"
62  
-      end
63  
-    end
64  
-  end
65  
-end

0 notes on commit 2a8357f

Please sign in to comment.
Something went wrong with that request. Please try again.