Sha256: cc1f42ad9a11cb9a4e561df0f682fb4923f4da26ee9d8d71587a7d9fae35af67

Contents?: true

Size: 1.81 KB

Versions: 56

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
require 'fedux_org_stdlib/require_files'
require_library %w(fileutils launchy)

require 'fedux_org_stdlib/logging/logger'
require 'fedux_org_stdlib/project/logger'
require 'fedux_org_stdlib/project/generators/taskjuggler'

module FeduxOrgStdlib
  # Project
  module Project
    # Taskjugger report
    class Report
      attr_reader :directory, :file

      private

      attr_reader :output_file, :plan, :output_directory, :generator

      public

      # Create a new report
      #
      # @param [Plan] plan
      #   Project plan to be used for report
      # @param [String] output_file
      #   The main output file for the report
      # @param [Generator] generator
      #   A generator to be used to be generator the report
      def initialize(
        plan:,
        output_file:,
        generator: FeduxOrgStdlib::Project::Generators::Taskjuggler.new
      )
        @plan             = plan
        @output_directory = File.dirname(output_file)
        @output_file      = output_file
        @generator        = generator
      end

      # Generate report
      def generate
        prepare_environment

        if output_file_does_not_exist? || plan_is_newer_than_output_file?
          generator.generate_report(output_directory, plan)
        else
          FeduxOrgStdlib::Project.logger.warn "No need to re-generate report. The plan file \"#{plan}\" is NOT newer than output \"#{@output_file}\"."
        end
      end

      # Open report in web browser
      def open
        Launchy.open(output_file)
      end

      private

      def prepare_environment
        FileUtils.mkdir_p output_directory
      end

      def output_file_does_not_exist?
        !File.exist? output_file
      end

      def plan_is_newer_than_output_file?
        plan.needs_to_be_compiled? output_file
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.18 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.11 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.9 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.8 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.7 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.6 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.5 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.4 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.3 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.2 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.1 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.11.0 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.10.9 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.10.8 lib/fedux_org_stdlib/project/report.rb
fedux_org-stdlib-0.10.7 lib/fedux_org_stdlib/project/report.rb