Kouhei Sutou
null+****@clear*****
Wed Jun 1 15:04:30 JST 2016
Kouhei Sutou 2016-06-01 15:04:30 +0900 (Wed, 01 Jun 2016) New Revision: 818d4146ffbd44ae20e08613c76deaaed78699c7 https://github.com/groonga/grntest/commit/818d4146ffbd44ae20e08613c76deaaed78699c7 Message: Extract variable expand code Added files: lib/grntest/variable-expander.rb Modified files: lib/grntest/executors/base-executor.rb Modified: lib/grntest/executors/base-executor.rb (+3 -8) =================================================================== --- lib/grntest/executors/base-executor.rb 2016-05-25 16:33:13 +0900 (7f9e20e) +++ lib/grntest/executors/base-executor.rb 2016-06-01 15:04:30 +0900 (c90c5cd) @@ -25,6 +25,7 @@ require "grntest/query-log-parser" require "grntest/execution-context" require "grntest/response-parser" require "grntest/template-evaluator" +require "grntest/variable-expander" module Grntest module Executors @@ -160,14 +161,8 @@ module Grntest end def expand_variables(string) - string.gsub(/\#{(.+?)}/) do |matched| - case $1 - when "db_path" - @context.db_path.to_s - else - matched - end - end + expander = VariableExpander.new(@context) + expander.expand(string) end def execute_directive_copy_path(line, content, options) Added: lib/grntest/variable-expander.rb (+33 -0) 100644 =================================================================== --- /dev/null +++ lib/grntest/variable-expander.rb 2016-06-01 15:04:30 +0900 (afc9846) @@ -0,0 +1,33 @@ +# Copyright (C) 2016 Kouhei Sutou <kou �� clear-code.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +module Grntest + class VariableExpander + def initialize(context) + @context = context + end + + def expand(string) + string.gsub(/\#{(.+?)}/) do |matched| + case $1 + when "db_path" + @context.db_path.to_s + else + matched + end + end + end + end +end -------------- next part -------------- HTML����������������������������...Télécharger