[Groonga-commit] ranguba/chupa-text at b3c7f73 [master] Support loading configuration file from load path

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Jan 3 18:04:24 JST 2014


Kouhei Sutou	2014-01-03 18:04:24 +0900 (Fri, 03 Jan 2014)

  New Revision: b3c7f73f94aae58ab9040623dccaa26e183ddc16
  https://github.com/ranguba/chupa-text/commit/b3c7f73f94aae58ab9040623dccaa26e183ddc16

  Message:
    Support loading configuration file from load path

  Modified files:
    chupa-text.gemspec
    lib/chupa-text/configuration-loader.rb
  Renamed files:
    data/chupa-text.conf
      (from chupa-text.conf)

  Modified: chupa-text.gemspec (+1 -0)
===================================================================
--- chupa-text.gemspec    2014-01-03 17:34:05 +0900 (f9ddd6b)
+++ chupa-text.gemspec    2014-01-03 18:04:24 +0900 (d963d98)
@@ -41,6 +41,7 @@ Gem::Specification.new do |spec|
   spec.license = "LGPLv2.1 or later"
   spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
   spec.files += [".yardopts"]
+  spec.files += Dir.glob("data/*.conf")
   spec.files += Dir.glob("lib/**/*.rb")
   spec.files += Dir.glob("doc/text/*")
   spec.test_files += Dir.glob("test/**/*")

  Renamed: data/chupa-text.conf (+0 -0) 100%
===================================================================

  Modified: lib/chupa-text/configuration-loader.rb (+15 -0)
===================================================================
--- lib/chupa-text/configuration-loader.rb    2014-01-03 17:34:05 +0900 (a96f038)
+++ lib/chupa-text/configuration-loader.rb    2014-01-03 18:04:24 +0900 (2d22e57)
@@ -20,9 +20,13 @@ module ChupaText
   class ConfigurationLoader
     def initialize(configuration=nil)
       @configuration = configuration || Configuration.new
+      @load_paths = []
+      data_dir = File.join(File.dirname(__FILE__), "..", "..", "data")
+      @load_paths << File.expand_path(data_dir)
     end
 
     def load(path)
+      path = resolve_path(path)
       File.open(path) do |file|
         instance_eval(file.read, path, 1)
       end
@@ -32,6 +36,17 @@ module ChupaText
       DecomposerConfigurationLoader.new(@configuration.decomposer)
     end
 
+    private
+    def resolve_path(path)
+      return path if File.exist?(path)
+      return path if Pathname(path).absolute?
+      @load_paths.each do |load_path|
+        resolved_path = File.join(load_path, path)
+        return resolved_path if File.exist?(resolved_path)
+      end
+      path
+    end
+
     class DecomposerConfigurationLoader
       def initialize(configuration)
         @configuration = configuration
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index