Class: Licensed::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/licensed/configuration.rb', line 7

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

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



23
24
25
# File 'lib/licensed/configuration.rb', line 23

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

#enabled?(source_type) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/licensed/configuration.rb', line 39

def enabled?(source_type)
  self["sources"].fetch(source_type, true)
end

#ignore(dependency) ⇒ Object



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

def ignore(dependency)
  (self["ignored"][dependency["type"]] ||= []) << dependency["name"]
end

#ignored?(dependency) ⇒ Boolean

Is the given dependency ignored?

Returns:

  • (Boolean)


49
50
51
# File 'lib/licensed/configuration.rb', line 49

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

#pathObject



19
20
21
# File 'lib/licensed/configuration.rb', line 19

def path
  Pathname.new("vendor/licenses")
end

#pwdObject



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

def pwd
  Pathname.new(Dir.pwd)
end

#review(dependency) ⇒ Object



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

def review(dependency)
  (self["reviewed"][dependency["type"]] ||= []) << dependency["name"]
end

#reviewed?(dependency) ⇒ Boolean

Is the given dependency approved?

Returns:

  • (Boolean)


44
45
46
# File 'lib/licensed/configuration.rb', line 44

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

#sourcesObject



31
32
33
34
35
36
37
# File 'lib/licensed/configuration.rb', line 31

def sources
  @sources ||= [
    Source::Bundler.new(self),
    Source::Bower.new(self),
    Source::NPM.new(self)
  ].select(&:enabled?)
end

#whitelist(license) ⇒ Object



66
67
68
# File 'lib/licensed/configuration.rb', line 66

def whitelist(license)
  self["whitelist"] << license
end

#whitelisted?(dependency) ⇒ Boolean

Is the license of the dependency whitelisted?

Returns:

  • (Boolean)


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

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