diff options
author | Toshiaki Asai <toshi.alternative@gmail.com> | 2016-02-28 21:46:14 +0900 |
---|---|---|
committer | Toshiaki Asai <toshi.alternative@gmail.com> | 2016-02-28 21:46:14 +0900 |
commit | d43f68e8bbb936150a0809ae6d13d9751b81dc16 (patch) | |
tree | 60522d2ee899da289ac8774554d67f05a48bfb7c | |
parent | 17bbbaaf6736e58e954cd2c6e8444bed0312de94 (diff) | |
download | mikutter-d43f68e8bbb936150a0809ae6d13d9751b81dc16.tar.gz |
Plugin slugをspecファイルに解決するto_spec
-rw-r--r-- | core/miquire_plugin.rb | 21 | ||||
-rw-r--r-- | core/miquire_to_spec.rb | 21 |
2 files changed, 27 insertions, 15 deletions
diff --git a/core/miquire_plugin.rb b/core/miquire_plugin.rb index 4be24512..721334a8 100644 --- a/core/miquire_plugin.rb +++ b/core/miquire_plugin.rb @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -miquire :core, "miquire", "plugin" +miquire :core, "miquire", "plugin", "miquire_to_spec" # プラグインのロードに関すること module Miquire::Plugin class << self + using Miquire::ToSpec include Enumerable # ロードパスの配列を返す。 @@ -103,20 +104,10 @@ module Miquire::Plugin exception: e, description: e.to_s) end } end - def load(spec) - type_strict spec => tcor(Hash, Symbol, String) - case spec - when Symbol, String - spec = spec.to_sym - if ::Plugin.instance_exist?(spec) - return true end - spec = get_spec_by_slug(spec) - if not spec - return false end - else - if ::Plugin.instance_exist?(spec[:slug]) - return true end end - + def load(_spec) + spec = _spec.to_spec + return false unless spec + return true if ::Plugin.instance_exist?(spec[:slug]) if defined?(spec[:depends][:mikutter]) and spec[:depends][:mikutter] version = Environment::Version.new(*(spec[:depends][:mikutter].split(".").map(&:to_i) + ([0]*4))[0...4]) if Environment::VERSION < version diff --git a/core/miquire_to_spec.rb b/core/miquire_to_spec.rb new file mode 100644 index 00000000..45dcb035 --- /dev/null +++ b/core/miquire_to_spec.rb @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +module Miquire::ToSpec + refine Symbol do + def to_spec + Miquire::Plugin.get_spec_by_slug(self) + end + end + + refine String do + def to_spec + to_sym.to_spec + end + end + + refine Hash do + def to_spec + self + end + end +end |