Kouhei Sutou
null+****@clear*****
Sun Jan 5 14:46:48 JST 2014
Kouhei Sutou 2014-01-05 14:46:48 +0900 (Sun, 05 Jan 2014) New Revision: 056a5b88eef00690b7026dc6db52b087dafb6987 https://github.com/ranguba/chupa-text/commit/056a5b88eef00690b7026dc6db52b087dafb6987 Message: chupa-text: loads decomposers installed by RubyGems by default Modified files: lib/chupa-text/command/chupa-text.rb lib/chupa-text/decomposers.rb test/command/test-chupa-text.rb Modified: lib/chupa-text/command/chupa-text.rb (+11 -1) =================================================================== --- lib/chupa-text/command/chupa-text.rb 2014-01-05 00:06:50 +0900 (1564212) +++ lib/chupa-text/command/chupa-text.rb 2014-01-05 14:46:48 +0900 (9a9b270) @@ -29,12 +29,13 @@ module ChupaText def initialize @input = nil @configuration = Configuration.default + @enable_gems = true end def run(*arguments) return false unless parse_arguments(arguments) - Decomposers.load + load_decomposers extractor = create_extractor data = create_data formatter = create_formatter @@ -77,9 +78,18 @@ module ChupaText "Read configuration from FILE.") do |path| load_configuration(path) end + parser.on("--disable-gems", + "Disable decomposers installed by RubyGems.") do + @enable_gems = false + end parser end + def load_decomposers + Decomposers.enable_all_gems if @enable_gems + Decomposers.load + end + def create_extractor extractor = Extractor.new extractor.apply_configuration(@configuration) Modified: lib/chupa-text/decomposers.rb (+14 -0) =================================================================== --- lib/chupa-text/decomposers.rb 2014-01-05 00:06:50 +0900 (8e4a63e) +++ lib/chupa-text/decomposers.rb 2014-01-05 14:46:48 +0900 (7fc4c06) @@ -17,6 +17,20 @@ module ChupaText module Decomposers class << self + def enable_all_gems + decomposer_specs = Gem::Specification.find_all do |spec| + spec.name.start_with?("chupa-text-decomposer-") + end + grouped_decomposer_specs = decomposer_specs.group_by(&:name) + latest_decomposer_specs = [] + grouped_decomposer_specs.each do |name, specs| + latest_decomposer_specs << specs.sort_by(&:version).last + end + latest_decomposer_specs.each do |spec| + gem(spec.name, spec.version) + end + end + def load paths = [] $LOAD_PATH.each do |load_path| Modified: test/command/test-chupa-text.rb (+1 -1) =================================================================== --- test/command/test-chupa-text.rb 2014-01-05 00:06:50 +0900 (e98b8d1) +++ test/command/test-chupa-text.rb 2014-01-05 14:46:48 +0900 (6bcebee) @@ -44,7 +44,7 @@ class TestCommandChupaText < Test::Unit::TestCase def run_command(*arguments) succeeded = wrap_io do - ChupaText::Command::ChupaText.run(*arguments) + ChupaText::Command::ChupaText.run("--disable-gems", *arguments) end [succeeded, JSON.parse(@stdout.string)] end -------------- next part -------------- HTML����������������������������...Download