Class: Licensed::Configuration
- Inherits:
-
Hash
- Object
- Hash
- Licensed::Configuration
- Defined in:
- lib/licensed/configuration.rb
Instance Attribute Summary collapse
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #config_path ⇒ Object
- #enabled?(source_type) ⇒ Boolean
- #ignore(dependency) ⇒ Object
-
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?.
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #path ⇒ Object
- #path=(value) ⇒ Object
- #pwd ⇒ Object
- #review(dependency) ⇒ Object
-
#reviewed?(dependency) ⇒ Boolean
Is the given dependency approved?.
- #sources ⇒ Object
- #whitelist(license) ⇒ Object
-
#whitelisted?(dependency) ⇒ Boolean
Is the license of the dependency whitelisted?.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/licensed/configuration.rb', line 7 def initialize( = {}) super() self.path = ["license-dir"] if ["license-dir"] update config_path.exist? ? YAML.load_file(config_path) : {} self["sources"] ||= {} self["reviewed"] ||= {} self["ignored"] ||= {} self["whitelist"] ||= [] @ui = Licensed::UI::Shell.new end |
Instance Attribute Details
#ui ⇒ Object
Returns the value of attribute ui.
5 6 7 |
# File 'lib/licensed/configuration.rb', line 5 def ui @ui end |
Instance Method Details
#config_path ⇒ Object
28 29 30 |
# File 'lib/licensed/configuration.rb', line 28 def config_path path.join("config.yml") end |
#enabled?(source_type) ⇒ Boolean
48 49 50 |
# File 'lib/licensed/configuration.rb', line 48 def enabled?(source_type) self["sources"].fetch(source_type, true) end |
#ignore(dependency) ⇒ Object
67 68 69 |
# File 'lib/licensed/configuration.rb', line 67 def ignore(dependency) (self["ignored"][dependency["type"]] ||= []) << dependency["name"] end |
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?
58 59 60 |
# File 'lib/licensed/configuration.rb', line 58 def ignored?(dependency) Array(self["ignored"][dependency["type"]]).include?(dependency["name"]) end |
#path ⇒ Object
20 21 22 |
# File 'lib/licensed/configuration.rb', line 20 def path @path ||= Pathname.new("vendor/licenses") end |
#path=(value) ⇒ Object
24 25 26 |
# File 'lib/licensed/configuration.rb', line 24 def path=(value) @path = Pathname.new(value) end |
#pwd ⇒ Object
32 33 34 |
# File 'lib/licensed/configuration.rb', line 32 def pwd Pathname.new(Dir.pwd) end |
#review(dependency) ⇒ Object
71 72 73 |
# File 'lib/licensed/configuration.rb', line 71 def review(dependency) (self["reviewed"][dependency["type"]] ||= []) << dependency["name"] end |
#reviewed?(dependency) ⇒ Boolean
Is the given dependency approved?
53 54 55 |
# File 'lib/licensed/configuration.rb', line 53 def reviewed?(dependency) Array(self["reviewed"][dependency["type"]]).include?(dependency["name"]) end |
#sources ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/licensed/configuration.rb', line 36 def sources @sources ||= [ Source::Bundler.new(self), Source::Bower.new(self), Source::Cabal.new(self), Source::Go.new(self), Source::Manifest.new(self), Source::NPM.new(self), Source::Stack.new(self) ].select(&:enabled?) end |
#whitelist(license) ⇒ Object
75 76 77 |
# File 'lib/licensed/configuration.rb', line 75 def whitelist(license) self["whitelist"] << license end |
#whitelisted?(dependency) ⇒ Boolean
Is the license of the dependency whitelisted?
63 64 65 |
# File 'lib/licensed/configuration.rb', line 63 def whitelisted?(dependency) Array(self["whitelist"]).include?(dependency["license"]) end |