require "pathname" module Licensed class Configuration < Hash attr_accessor :ui def initialize super() update config_path.exist? ? YAML.load_file(config_path) : {} self["sources"] ||= {} self["reviewed"] ||= {} self["ignored"] ||= {} self["whitelist"] ||= [] @ui = Licensed::UI::Shell.new end def path Pathname.new("vendor/licenses") end def config_path path.join("config.yml") end def pwd Pathname.new(Dir.pwd) end def sources @sources ||= [ Source::Bundler.new(self), Source::Bower.new(self), Source::NPM.new(self) ].select(&:enabled?) end def enabled?(source_type) self["sources"].fetch(source_type, true) end # Is the given dependency approved? def reviewed?(dependency) Array(self["reviewed"][dependency["type"]]).include?(dependency["name"]) end # Is the given dependency ignored? def ignored?(dependency) Array(self["ignored"][dependency["type"]]).include?(dependency["name"]) end # Is the license of the dependency whitelisted? def whitelisted?(dependency) Array(self["whitelist"]).include?(dependency["license"]) end def ignore(dependency) (self["ignored"][dependency["type"]] ||= []) << dependency["name"] end def review(dependency) (self["reviewed"][dependency["type"]] ||= []) << dependency["name"] end def whitelist(license) self["whitelist"] << license end end end