Module: Soaspec::ExeHelpers
- Defined in:
- lib/soaspec/exe_helpers.rb
Overview
Help with tasks common to soaspec executables
Instance Method Summary collapse
-
#class_content ⇒ String
Create class representing wsdl in general.
- #create_file(filename: nil, content: nil, ignore_if_present: false, erb: true) ⇒ Object
- #create_files(filenames) ⇒ Object
-
#create_files_for(type) ⇒ Object
Create files in project depending on type of project.
-
#create_folder(folder) ⇒ Object
Create folder if there’s not a file already there.
-
#generated_soap_spec_for(operation) ⇒ Object
Create a spec for an WSDL operation.
-
#retrieve_contents(filename, erb = true) ⇒ Object
Retrieve default file contents based on filename.
-
#spec_task ⇒ Object
Spec task string depending upon whether virtual is used.
Instance Method Details
#class_content ⇒ String
Returns Create class representing wsdl in general.
76 77 78 |
# File 'lib/soaspec/exe_helpers.rb', line 76 def class_content ERB.new(File.read(File.join(File.dirname(__FILE__), 'generator', 'lib/dynamic_class_content.rb.erb'))).result(binding) end |
#create_file(filename: nil, content: nil, ignore_if_present: false, erb: true) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/soaspec/exe_helpers.rb', line 48 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 else File.open(filename, 'w') { |f| f.puts content } puts 'Created: ' + filename end end |
#create_files(filenames) ⇒ Object
22 23 24 25 |
# File 'lib/soaspec/exe_helpers.rb', line 22 def create_files(filenames) raise ArgumentError, 'Expected filenames to be an Array' unless filenames.is_a? Array filenames.each { |name| create_file filename: name } end |
#create_files_for(type) ⇒ Object
Create files in project depending on type of project
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/soaspec/exe_helpers.rb', line 9 def create_files_for(type) case type when 'soap' create_files %w[lib/blz_service.rb lib/shared_example.rb spec/soap_spec.rb] create_file(filename: 'template/soap_template.xml', erb: false) when 'rest' create_files %w[spec/rest_spec.rb lib/package_service.rb] else # TODO: This needs to have placeholders explaining what to fill in end end |
#create_folder(folder) ⇒ Object
Create folder if there’s not a file already there. Will create parent folder if necessary.
66 67 68 69 70 71 72 73 |
# File 'lib/soaspec/exe_helpers.rb', line 66 def create_folder(folder) if File.exist? folder warn "!! #{folder} already exists and is not a directory" unless File.directory? folder else FileUtils.mkdir_p folder puts "Created folder: #{folder}/" end end |
#generated_soap_spec_for(operation) ⇒ Object
Create a spec for an WSDL operation
82 83 84 |
# File 'lib/soaspec/exe_helpers.rb', line 82 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 |
#retrieve_contents(filename, erb = true) ⇒ Object
Retrieve default file contents based on filename
36 37 38 39 40 41 42 43 44 |
# File 'lib/soaspec/exe_helpers.rb', line 36 def retrieve_contents(filename, erb = true) default_file = if filename.start_with?('../') File.join(File.dirname(__FILE__), filename[3..-1] + (erb ? '.erb' : '')) else File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : '')) end contents = File.read(default_file) erb ? ERB.new(contents).result(binding) : contents end |
#spec_task ⇒ Object
Spec task string depending upon whether virtual is used
28 29 30 31 |
# File 'lib/soaspec/exe_helpers.rb', line 28 def spec_task task_name = [:virtual] ? 'spec: :start_test_server' : ':spec' "RSpec::Core::RakeTask.new(#{task_name}) do |t|" end |