aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/miquire.rb35
-rw-r--r--test/core/test_miquire.rb20
2 files changed, 52 insertions, 3 deletions
diff --git a/core/miquire.rb b/core/miquire.rb
index 989be751..6c34b4a2 100644
--- a/core/miquire.rb
+++ b/core/miquire.rb
@@ -129,6 +129,41 @@ module Miquire
detected << file end } }
detected.sort.each &Proc.new end
+ def each_spec
+ each{ |path|
+ spec = get_spec path
+ yield spec if spec } end
+
+ def to_hash
+ result = {}
+ each_spec{ |spec|
+ result[spec[:slug]] = spec }
+ result end
+
+ # 受け取ったパスにあるプラグインのスラッグを返す
+ # ==== Args
+ # [path] パス(String)
+ # ==== Return
+ # プラグインスラッグ(Symbol)
+ def get_slug(path)
+ spec = get_spec(path)
+ if spec
+ spec[:slug]
+ else
+ File.basename(path, ".rb").to_sym end end
+
+ # specファイルがあればそれを返す
+ # ==== Args
+ # [path] パス(String)
+ # ==== Return
+ # specファイルの内容か、存在しなければnil
+ def get_spec(path)
+ plugin_dir = FileTest.directory?(path) ? path : File.dirname(path)
+ spec_filename = File.join(plugin_dir, "spec")
+ if FileTest.exist? spec_filename
+ spec = YAML.load_file(spec_filename).symbolize
+ spec[:path] = plugin_dir
+ spec end end
end
end
end
diff --git a/test/core/test_miquire.rb b/test/core/test_miquire.rb
index 7394904b..01817df5 100644
--- a/test/core/test_miquire.rb
+++ b/test/core/test_miquire.rb
@@ -41,8 +41,22 @@ class TC_Miquire < Test::Unit::TestCase
miquire :allfiles
end
- # must "enum plugins" do
- # Miquire::Plugin.loadpath << 'addon/'
- # end
+ must "get plugin slug by path (spec exist)" do
+ assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/'))))
+ end
+
+ must "get plugin slug by path (spec not exist)" do
+ Miquire::Plugin.stubs(:get_spec).returns(false)
+ assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/'))))
+ assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/rest.rb'))))
+ end
+
+ must "to_hash plugin slug and path" do
+ p Miquire::Plugin.to_hash
+ end
+
+ must "load a plugin and depends" do
+ #Miquire::Plugin.load(:home_timeline)
+ end
end