Sha256: 7b75f0af67b999f57db9749ca9dca37a28c4cdc4683d86a134d0526642e4e298

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module Massa
  class Tool
    attr_reader :name, :description, :gem, :command, :required

    def initialize(name, attributes)
      @name        = name
      @description = attributes['description']
      @gem         = attributes['gem'].nil? ? true : attributes['gem']
      @command     = attributes['command']
      @required    = attributes['required'].nil? ? true : attributes['required']
    end

    alias required? required
    alias gem?      gem

    class << self
      def list
        tools = custom_tools.any? ? custom_tools : default_tools

        tools.map { |name, attributes| new(name, attributes) }
      end

      private

      def default_tools
        @default_tools ||= YAML.load_file(config_file_from_gem)
      end

      def custom_tools
        # Returns an empty hash if config file is empty
        @custom_tools ||= YAML.load_file(config_file_from_project) || {}

      # When there is no config file in the project
      rescue Errno::ENOENT
        {}
      end

      def config_file_from_gem
        File.expand_path('../../config/default_tools.yml', __dir__)
      end

      def config_file_from_project
        "#{Dir.pwd}/config/massa.yml"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
massa-0.6.0 lib/massa/tool.rb