Sha256: 950536a970763435669e901dc471857b71edacdb486299bfe32df2ef9b15bc5d

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require_relative "generate_domain"

module Foobara
  module Generators
    module DomainGenerator
      class WriteDomainToDisk < Foobara::Generators::WriteGeneratedFilesToDisk
        class << self
          def generator_key
            "domain"
          end
        end

        depends_on GenerateDomain

        inputs do
          domain_config DomainConfig, :required
          # TODO: should be able to delete this and inherit it
          output_directory :string
        end

        def execute
          generate_file_contents
          write_all_files_to_disk
          run_post_generation_tasks

          stats
        end

        def output_directory
          inputs[:output_directory] || default_output_directory
        end

        def default_output_directory
          "."
        end

        def generate_file_contents
          # TODO: just pass this in as the inputs instead of the domain??
          self.paths_to_source_code = run_subcommand!(GenerateDomain, domain_config.attributes)
        end

        def run_post_generation_tasks
          Dir.chdir output_directory do
            rubocop_autocorrect
          end
        end

        def rubocop_autocorrect
          # :nocov:
          Open3.popen3("bundle exec rubocop --no-server -A") do |_stdin, _stdout, stderr, wait_thr|
            exit_status = wait_thr.value
            unless exit_status.success?
              raise "could not rubocop -A. #{stderr.read}"
            end
          end
          # :nocov:
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foobara-domain-generator-0.0.2 src/write_domain_to_disk.rb
foobara-domain-generator-0.0.1 src/write_domain_to_disk.rb