Sha256: 709641b33303280051dc1f4e19426ff2de2ecf1b2b76d7f5930455aea6d7e818

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', __FILE__)
      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.2.0.rc1 lib/massa/tool.rb