From cd072c1d4cd3f2e2a93819566d895a9e01a434c3 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 9 Oct 2012 14:45:27 -0400 Subject: [PATCH] more refactoring --- .../given/i_am_on_the_linux_platform.rb | 2 +- lib/penchant.rb | 1 - lib/penchant/file_processor.rb | 58 +++++++++++++++++ lib/penchant/gemfile.rb | 2 +- lib/penchant/penchant_file.rb | 62 ------------------- 5 files changed, 60 insertions(+), 65 deletions(-) delete mode 100644 lib/penchant/penchant_file.rb diff --git a/features/step_definitions/given/i_am_on_the_linux_platform.rb b/features/step_definitions/given/i_am_on_the_linux_platform.rb index 654abda..bfa33b0 100644 --- a/features/step_definitions/given/i_am_on_the_linux_platform.rb +++ b/features/step_definitions/given/i_am_on_the_linux_platform.rb @@ -1,3 +1,3 @@ Given /^I am on the "([^"]*)" platform$/ do |os| - Penchant::PenchantFile.any_instance.stubs(:current_os).returns(os.to_sym) + Penchant::FileProcessor.any_instance.stubs(:current_os).returns(os.to_sym) end diff --git a/lib/penchant.rb b/lib/penchant.rb index 0b75569..3dc0c09 100644 --- a/lib/penchant.rb +++ b/lib/penchant.rb @@ -5,7 +5,6 @@ module Penchant autoload :Hooks, 'penchant/hooks' autoload :Env, 'penchant/env' autoload :FileProcessor, 'penchant/file_processor' - autoload :PenchantFile, 'penchant/penchant_file' autoload :Defaults, 'penchant/defaults' autoload :CustomProperty, 'penchant/custom_property' autoload :PropertyStack, 'penchant/property_stack' diff --git a/lib/penchant/file_processor.rb b/lib/penchant/file_processor.rb index 747f229..7071aea 100644 --- a/lib/penchant/file_processor.rb +++ b/lib/penchant/file_processor.rb @@ -160,6 +160,64 @@ module Penchant host_os[%r{^[a-z]+}, 1].to_sym end end + + def handle_result(data) + instance_eval(data) + end + + def gem(*args) + gem_name = [ args.shift ] + template = {} + + if args.last.kind_of?(::Hash) + template = args.pop + end + + version = args.first + + options = @properties.create_stack_for(template, @_strip_pathing_options).process_for_gem(gem_name.first, @_current_env_defaults) + + args = [ gem_name.first ] + args << version if version + + if options[:git] + @defined_git_repos << Penchant::Repo.new(options[:git]) + end + + args << options if !options.empty? + + self << %{gem #{args_to_string(args)}} + end + + def gemspec + @output << %{gemspec} + end + + def gems(*args) + gems, template = split_args(args) + + gems.flatten.each do |gem_name| + options = @properties.create_stack_for(template, @_strip_pathing_options).process_for_gem(gem_name) + + args = [ gem_name ] + args << options if !options.empty? + + gem *args + end + end + + def group(*args, &block) + self << "" + self << %{group #{args_to_string(args)} do} + + call_and_indent_output(block) + + self << %{end} + end + + def source(*args) + self << %{source #{args_to_string(args)}} + end end end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index da4d22d..4877135 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -123,7 +123,7 @@ module Penchant end def builder - @builder ||= PenchantFile.new(template) + @builder ||= FileProcessor.new(template) end def template diff --git a/lib/penchant/penchant_file.rb b/lib/penchant/penchant_file.rb deleted file mode 100644 index 0a1bfbd..0000000 --- a/lib/penchant/penchant_file.rb +++ /dev/null @@ -1,62 +0,0 @@ -module Penchant - class PenchantFile < FileProcessor - def handle_result(data) - instance_eval(data) - end - - def gem(*args) - gem_name = [ args.shift ] - template = {} - - if args.last.kind_of?(::Hash) - template = args.pop - end - - version = args.first - - options = @properties.create_stack_for(template, @_strip_pathing_options).process_for_gem(gem_name.first, @_current_env_defaults) - - args = [ gem_name.first ] - args << version if version - - if options[:git] - @defined_git_repos << Penchant::Repo.new(options[:git]) - end - - args << options if !options.empty? - - self << %{gem #{args_to_string(args)}} - end - - def gemspec - @output << %{gemspec} - end - - def gems(*args) - gems, template = split_args(args) - - gems.flatten.each do |gem_name| - options = @properties.create_stack_for(template, @_strip_pathing_options).process_for_gem(gem_name) - - args = [ gem_name ] - args << options if !options.empty? - - gem *args - end - end - - def group(*args, &block) - self << "" - self << %{group #{args_to_string(args)} do} - - call_and_indent_output(block) - - self << %{end} - end - - def source(*args) - self << %{source #{args_to_string(args)}} - end - end -end -