Sha256: 0db693cc5827a6117404b6dddd6fb803f8d1c76ef56d82619f5de4b6657b2cfc

Contents?: true

Size: 1.67 KB

Versions: 19

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

# takelage project module
module ProjectModule
  # takelage config class.
  class TakelageProject
    include Singleton
    include LoggingModule
    include SystemModule
    include ConfigModule

    attr_accessor :active, :private, :main

    def initialize
      @active = {}
      @private = {}
      @main = {}
    end
  end

  # Initialze project
  def initialize_project
    TakelageProject.instance.main = _project_read_main
    TakelageProject.instance.private = _project_read_private
    TakelageProject.instance.active = _project_merge_active
  end

  # @return [Object] global singleton project
  def project
    TakelageProject.instance
  end

  private

  # Read main YAML file.
  def _project_read_main
    _rakefile, @path = Rake.application.find_rakefile_location
    main_file = "#{@path}/" \
        "#{TakelageProject.instance.config.active['info_project_main']}"

    return {} unless File.exist? main_file

    read_yaml_file(main_file).sort.to_h || {}
  end

  # Read private YAML file.
  def _project_read_private
    _rakefile, @path = Rake.application.find_rakefile_location
    private_file = "#{@path}/" \
        "#{TakelageProject.instance.config.active['info_project_private']}"

    return {} unless File.exist? private_file

    private_yaml = read_yaml_file(private_file) || {}

    private_yaml.sort.to_h
  end

  # Merge active configuration.
  def _project_merge_active
    # make a clone or else we'll change the original hash
    main = TakelageProject.instance.main.clone
    private = TakelageProject.instance.private.clone

    # merge main and private to active
    # private wins against main
    main.merge!(private).sort.to_h
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
takelage-0.20.1 lib/takelage/lib/project.rb
takelage-0.20.0 lib/takelage/lib/project.rb
takelage-0.19.2 lib/takelage/lib/project.rb
takelage-0.19.1 lib/takelage/lib/project.rb
takelage-0.19.0 lib/takelage/lib/project.rb
takelage-0.18.1 lib/takelage/lib/project.rb
takelage-0.18.0 lib/takelage/lib/project.rb
takelage-0.17.1 lib/takelage/lib/project.rb
takelage-0.17.0 lib/takelage/lib/project.rb
takelage-0.16.0 lib/takelage/lib/project.rb
takelage-0.15.1 lib/takelage/lib/project.rb
takelage-0.15.0 lib/takelage/lib/project.rb
takelage-0.14.5 lib/takelage/lib/project.rb
takelage-0.14.4 lib/takelage/lib/project.rb
takelage-0.14.3 lib/takelage/lib/project.rb
takelage-0.14.2 lib/takelage/lib/project.rb
takelage-0.14.1 lib/takelage/lib/project.rb
takelage-0.14.0 lib/takelage/lib/project.rb
takelage-0.13.3 lib/takelage/lib/project.rb