Sha256: 18f3588e1990872e81e7b0bff1f3cce76c52e0c92a4fe2cd783da7e0e7fd70c3

Contents?: true

Size: 1.88 KB

Versions: 13

Compression:

Stored size: 1.88 KB

Contents

# encoding: UTF-8

module Gjp
  # creates and updates spec files
  class SpecGenerator
    include Logger

    def initialize(project)
      @project = project
    end

    def generate_kit_spec
      @project.from_directory do
        spec_name = "#{@project.name}-kit.spec"
        spec_path = File.join("kit", spec_name)
        output_dir = File.join("output", "#{@project.name}-kit")
        FileUtils.mkdir_p(output_dir)

        adapter = Gjp::KitSpecAdapter.new(@project)
        conflict_count = generate_merging("kit.spec", adapter.get_binding, spec_path, :generate_kit_spec)

        symlink_to_output(spec_path, output_dir)

        [spec_path, conflict_count]
      end
    end

    def generate_package_spec(name, pom_path, filter)
      pom = Gjp::Pom.new(pom_path)
      @project.from_directory do
        spec_name = "#{name}.spec"
        spec_path = File.join("src", name, spec_name)
        output_dir = File.join("output", name)
        FileUtils.mkdir_p(output_dir)

        adapter = Gjp::PackageSpecAdapter.new(@project, name, pom, filter)
        conflict_count = generate_merging("package.spec", adapter.get_binding, spec_path, "generate_#{name}_spec")

        symlink_to_output(spec_path, output_dir)

        [spec_path, conflict_count]
      end
    end

    private

    # generates a spec file from a template and 3-way merges it
    def generate_merging(template, binding, path, tag_prefix)
      new_content = TemplateManager.new.generate(template, binding)
      @project.merge_new_content(new_content, path, "Spec generated", tag_prefix)      
    end

    # links a spec file in a subdirectory of output/
    def symlink_to_output(spec_path, destination_dir)
      spec_name = Pathname.new(spec_path).basename.to_s
      destination_spec_path = File.join(destination_dir, spec_name)
      FileUtils.symlink(File.expand_path(spec_path), destination_spec_path, :force => true)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gjp-0.36.0 lib/gjp/spec_generator.rb
gjp-0.35.0 lib/gjp/spec_generator.rb
gjp-0.34.0 lib/gjp/spec_generator.rb
gjp-0.33.0 lib/gjp/spec_generator.rb
gjp-0.32.0 lib/gjp/spec_generator.rb
gjp-0.31.0 lib/gjp/spec_generator.rb
gjp-0.30.0 lib/gjp/spec_generator.rb
gjp-0.29.0 lib/gjp/spec_generator.rb
gjp-0.28.0 lib/gjp/spec_generator.rb
gjp-0.27.0 lib/gjp/spec_generator.rb
gjp-0.26.0 lib/gjp/spec_generator.rb
gjp-0.25.0 lib/gjp/spec_generator.rb
gjp-0.24.0 lib/gjp/spec_generator.rb