Module: Soaspec::ExeHelpers
- Defined in:
- lib/soaspec/exe_helpers.rb
Overview
Help with tasks common to soaspec executables
Instance Method Summary collapse
-
#class_content ⇒ Object
Create class representing wsdl in general.
- #create_file(filename: nil, content: nil, ignore_if_present: false, erb: true) ⇒ Object
-
#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) ⇒ 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 ⇒ Object
Create class representing wsdl in general
50 51 52 |
# File 'lib/soaspec/exe_helpers.rb', line 50 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/soaspec/exe_helpers.rb', line 22 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_folder(folder) ⇒ Object
Create folder if there’s not a file already there. Will create parent folder if necessary.
40 41 42 43 44 45 46 47 |
# File 'lib/soaspec/exe_helpers.rb', line 40 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
56 57 58 |
# File 'lib/soaspec/exe_helpers.rb', line 56 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) ⇒ Object
Retrieve default file contents based on filename
14 15 16 17 18 |
# File 'lib/soaspec/exe_helpers.rb', line 14 def retrieve_contents(filename, erb) default_file = File.join(File.dirname(__FILE__), 'generator', filename + (erb ? '.erb' : '')) 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
8 9 10 11 |
# File 'lib/soaspec/exe_helpers.rb', line 8 def spec_task task_name = [:virtual] ? 'spec: :start_test_server' : ':spec' "RSpec::Core::RakeTask.new(#{task_name}) do |t|" end |