Sha256: 79c3e51da74f4398c9d479bc4f805450ceaa7b271c3763a9ca8e8332a4929bb8
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
# encoding: UTF-8 module Tetra # adds methods to generate a spec file from a package object module Speccable # saves a specfile for this object in correct directories # returns the spec path and the conflict count with the previously generated # version, if any # destination_dir/name/name.spec def _to_spec(project, name, template_spec_name, destination_dir) project.from_directory do spec_name = "#{name}.spec" spec_dir = File.join(destination_dir, name) FileUtils.mkdir_p(spec_dir) spec_path = File.join(spec_dir, spec_name) new_content = generate(template_spec_name, binding) label = "Spec for #{name} generated" conflict_count = project.merge_new_content(new_content, spec_path, label, "#{name}-spec") [spec_path, conflict_count] end end # returns the spec template path, exposed for testing def template_path File.join(File.dirname(__FILE__), "..", "..", "template") end private # generates content from an ERB template and an object binding # if destination_path is given, write it to that file, otherwise just # return it def generate(template_name, object_binding, destination_path = nil) erb = ERB.new File.read(File.join(template_path, template_name)), nil, "<>" new_content = erb.result(object_binding) unless destination_path.nil? File.open(destination_path, "w") { |io| io.write new_content } end new_content end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
tetra-0.52.0 | lib/tetra/packages/speccable.rb |
tetra-0.51.0 | lib/tetra/packages/speccable.rb |
tetra-0.50.0 | lib/tetra/packages/speccable.rb |
tetra-0.49.0 | lib/tetra/packages/speccable.rb |