瀏覽代碼

use define_singleton_method to dynamically create methods for config options

Chris Mague 7 年之前
父節點
當前提交
4d01ea809f
共有 1 個文件被更改,包括 5 次插入7 次删除
  1. 5 7
      lib/neoinfra/config.rb

+ 5 - 7
lib/neoinfra/config.rb

@@ -13,14 +13,12 @@ module NeoInfra
         File.join(File.dirname(File.expand_path(__FILE__)),
                   '..', '..', cfg)
       )
-    end
-
-    def neo4j
-      @config['neo4j']
-    end
 
-    def accounts
-      @config['accounts']
+      @config.keys.each do |c|
+        define_singleton_method(:"#{c}") do
+          @config[c]
+        end
+      end
     end
   end
 end