Class: Licensed::Configuration

Inherits:
Hash
  • Object
show all
Defined in:
lib/licensed/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  super()
  self.path = options["license-dir"] if options["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

#uiObject

Returns the value of attribute ui.



5
6
7
# File 'lib/licensed/configuration.rb', line 5

def ui
  @ui
end

Instance Method Details

#config_pathObject



28
29
30
# File 'lib/licensed/configuration.rb', line 28

def config_path
  path.join("config.yml")
end

#enabled?(source_type) ⇒ Boolean

Returns:

  • (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?

Returns:

  • (Boolean)


58
59
60
# File 'lib/licensed/configuration.rb', line 58

def ignored?(dependency)
  Array(self["ignored"][dependency["type"]]).include?(dependency["name"])
end

#pathObject



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

#pwdObject



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?

Returns:

  • (Boolean)


53
54
55
# File 'lib/licensed/configuration.rb', line 53

def reviewed?(dependency)
  Array(self["reviewed"][dependency["type"]]).include?(dependency["name"])
end

#sourcesObject



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?

Returns:

  • (Boolean)


63
64
65
# File 'lib/licensed/configuration.rb', line 63

def whitelisted?(dependency)
  Array(self["whitelist"]).include?(dependency["license"])
end