lib/massa/tool.rb in massa-0.1.5 vs lib/massa/tool.rb in massa-0.2.0.rc1

- old
+ new

@@ -1,25 +1,37 @@ # 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 - default_tools.each_with_object({}) do |(tool, options), hash| - hash[tool] = options.merge(custom_tools[tool] || {}) - hash - end + tools = custom_tools.any? ? custom_tools : default_tools + + tools.map { |name, attributes| new(name, attributes) } end private def default_tools - YAML.load_file(config_file_from_gem) + @default_tools ||= YAML.load_file(config_file_from_gem) end def custom_tools # Returns an empty hash if config file is empty - YAML.load_file(config_file_from_project) || {} + @custom_tools ||= YAML.load_file(config_file_from_project) || {} # When there is no config file in the project rescue Errno::ENOENT {} end