lib/soaspec/exe_helpers.rb in soaspec-0.2.8 vs lib/soaspec/exe_helpers.rb in soaspec-0.2.9

- old
+ new

@@ -1,11 +1,9 @@ - require 'fileutils' module Soaspec # Help with tasks common to soaspec executables module ExeHelpers - # Create files in project depending on type of project # @param [String] type Type of project to create, e.g., 'soap', 'rest' def create_files_for(type) case type when 'soap' @@ -17,13 +15,14 @@ # TODO: This needs to have placeholders explaining what to fill in end end # @param [Array] filenames List of files to create - def create_files(filenames) + def create_files(filenames, ignore_if_present: false) raise ArgumentError, 'Expected filenames to be an Array' unless filenames.is_a? Array - filenames.each { |name| create_file filename: name } + + filenames.each { |name| create_file filename: name, ignore_if_present: ignore_if_present } end # Spec task string depending upon whether virtual is used def spec_task task_name = options[:virtual] ? 'spec: :start_test_server' : ':spec' @@ -43,19 +42,19 @@ erb ? ERB.new(contents).result(binding) : contents end # @param [String] filename Name of the file to create # @param [String] content Content to place inside file + # @param [Boolean] ignore_if_present Don't complain if file is present def create_file(filename: nil, content: nil, ignore_if_present: false, erb: true) raise 'Need to pass filename' unless filename + content ||= retrieve_contents(filename, erb) create_folder File.split(filename).first if File.exist? filename old_content = File.read(filename) - if old_content != content && !ignore_if_present - warn "!! #{filename} already exists and differs from template" - end + warn "!! #{filename} already exists and differs from template" if old_content != content && !ignore_if_present else File.open(filename, 'w') { |f| f.puts content } puts 'Created: ' + filename end end @@ -80,8 +79,7 @@ # Create a spec for an WSDL operation # @param [String] operation Used in ERB to create a test for a WSDL operation def generated_soap_spec_for(operation) ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'spec/dynamic_soap_spec.rb.erb'))).result(binding) end - end -end \ No newline at end of file +end