Class: Licensed::AppConfiguration
- Inherits:
-
Hash
- Object
- Hash
- Licensed::AppConfiguration
- Defined in:
- lib/licensed/configuration.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CACHE_PATH =
".licenses".freeze
- DEFAULT_CONFIG_FILES =
[ ".licensed.yml".freeze, ".licensed.yaml".freeze, ".licensed.json".freeze ].freeze
Instance Method Summary collapse
-
#allow(license) ⇒ Object
Set a license as explicitly allowed.
-
#allowed?(dependency) ⇒ Boolean
Is the license of the dependency allowed?.
-
#cache_path ⇒ Object
Returns the path to the app cache directory as a Pathname.
-
#enabled?(source_type) ⇒ Boolean
Returns whether a source type is enabled.
-
#ignore(dependency) ⇒ Object
Ignore a dependency.
-
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?.
-
#initialize(options = {}, inherited_options = {}) ⇒ AppConfiguration
constructor
A new instance of AppConfiguration.
- #pwd ⇒ Object
-
#review(dependency) ⇒ Object
Set a dependency as reviewed.
-
#reviewed?(dependency) ⇒ Boolean
Is the given dependency reviewed?.
-
#root ⇒ Object
Returns the path to the workspace root as a Pathname.
-
#source_path ⇒ Object
Returns the path to the app source directory as a Pathname.
-
#sources ⇒ Object
Returns an array of enabled app sources.
Constructor Details
#initialize(options = {}, inherited_options = {}) ⇒ AppConfiguration
Returns a new instance of AppConfiguration.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/licensed/configuration.rb', line 13 def initialize( = {}, = {}) super() # update order: # 1. anything inherited from root config # 2. app defaults # 3. explicitly configured app settings update() update(defaults_for(, )) update() self["sources"] ||= {} self["reviewed"] ||= {} self["ignored"] ||= {} self["allowed"] ||= [] # default the root to the git repository root, # or the current directory if no other options are available self["root"] ||= Licensed::Git.repository_root || Dir.pwd verify_arg "source_path" verify_arg "cache_path" end |
Instance Method Details
#allow(license) ⇒ Object
Set a license as explicitly allowed
97 98 99 |
# File 'lib/licensed/configuration.rb', line 97 def allow(license) self["allowed"] << license end |
#allowed?(dependency) ⇒ Boolean
Is the license of the dependency allowed?
82 83 84 |
# File 'lib/licensed/configuration.rb', line 82 def allowed?(dependency) Array(self["allowed"]).include?(dependency["license"]) end |
#cache_path ⇒ Object
Returns the path to the app cache directory as a Pathname
44 45 46 |
# File 'lib/licensed/configuration.rb', line 44 def cache_path root.join(self["cache_path"]) end |
#enabled?(source_type) ⇒ Boolean
Returns whether a source type is enabled
65 66 67 68 69 |
# File 'lib/licensed/configuration.rb', line 65 def enabled?(source_type) # the default is false if any sources are set to true, true otherwise default = !self["sources"].any? { |_, enabled| enabled } self["sources"].fetch(source_type, default) end |
#ignore(dependency) ⇒ Object
Ignore a dependency
87 88 89 |
# File 'lib/licensed/configuration.rb', line 87 def ignore(dependency) (self["ignored"][dependency["type"]] ||= []) << dependency["name"] end |
#ignored?(dependency) ⇒ Boolean
Is the given dependency ignored?
77 78 79 |
# File 'lib/licensed/configuration.rb', line 77 def ignored?(dependency) Array(self["ignored"][dependency["type"]]).include?(dependency["name"]) end |
#pwd ⇒ Object
53 54 55 |
# File 'lib/licensed/configuration.rb', line 53 def pwd Pathname.pwd end |
#review(dependency) ⇒ Object
Set a dependency as reviewed
92 93 94 |
# File 'lib/licensed/configuration.rb', line 92 def review(dependency) (self["reviewed"][dependency["type"]] ||= []) << dependency["name"] end |
#reviewed?(dependency) ⇒ Boolean
Is the given dependency reviewed?
72 73 74 |
# File 'lib/licensed/configuration.rb', line 72 def reviewed?(dependency) Array(self["reviewed"][dependency["type"]]).include?(dependency["name"]) end |
#root ⇒ Object
Returns the path to the workspace root as a Pathname. Defaults to Licensed::Git.repository_root if not explicitly set
39 40 41 |
# File 'lib/licensed/configuration.rb', line 39 def root Pathname.new(self["root"]) end |
#source_path ⇒ Object
Returns the path to the app source directory as a Pathname
49 50 51 |
# File 'lib/licensed/configuration.rb', line 49 def source_path root.join(self["source_path"]) end |