Class: Aspisec::Module::Location
- Inherits:
-
Object
- Object
- Aspisec::Module::Location
- Defined in:
- lib-ruby/aspisec/module.rb
Overview
Object easing the manipulation of locations.
Helpers to get the path, check if this feature/file/directory is enabled, etc.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
Explanation of what the location (file / directory) is containing, to give an idea of how sensitive it is.
-
#name ⇒ String
readonly
Name of the feature, file or directory of the tool.
-
#path ⇒ Pathname
readonly
File path of the file or directory location to clean.
Instance Method Summary collapse
-
#enabled? ⇒ true|false
Is this location enabled?.
-
#exist? ⇒ true|false
Check if the location exist (weither it's a file, directory or a path contaning globbing so multiple files / directories).
-
#initialize(tool_conf, feature_name) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(tool_conf, feature_name) ⇒ Location
Returns a new instance of Location.
100 101 102 103 104 105 |
# File 'lib-ruby/aspisec/module.rb', line 100 def initialize(tool_conf, feature_name) @name = feature_name @path = Pathname.new(tool_conf.dig('location', @name, 'path')) @enabled = tool_conf.dig('location', @name).fetch('enabled', true) @description = tool_conf.dig('location', @name).fetch('description', '') end |
Instance Attribute Details
#description ⇒ String (readonly)
Explanation of what the location (file / directory) is containing, to give an idea of how sensitive it is.
95 96 97 |
# File 'lib-ruby/aspisec/module.rb', line 95 def description @description end |
#name ⇒ String (readonly)
Name of the feature, file or directory of the tool.
87 88 89 |
# File 'lib-ruby/aspisec/module.rb', line 87 def name @name end |
#path ⇒ Pathname (readonly)
File path of the file or directory location to clean.
91 92 93 |
# File 'lib-ruby/aspisec/module.rb', line 91 def path @path end |
Instance Method Details
#enabled? ⇒ true|false
Is this location enabled?
109 110 111 |
# File 'lib-ruby/aspisec/module.rb', line 109 def enabled? @enabled end |
#exist? ⇒ true|false
Check if the location exist (weither it's a file, directory or a path contaning globbing so
multiple files / directories).
loc.path.exist? will return false when a path contains globbing as it's not expended,
that's the main reason for creating the loc.exist? helper.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib-ruby/aspisec/module.rb', line 118 def exist? return true if path.exist? # this case is needed to support globbing candidates = Dir[path].map { |path| Pathname.new(path).exist? } # rubocop:disable Lint/DuplicateBranch # false positive in rubocop rule if candidates.empty? # necessary because [].all? always return true whatever the condition is # this is preventing doing a simple one-liner like # self.path.exist? || Dir[self.path].map { |path| Pathname.new(path).exist? }.all? { |bool| bool == true } false elsif candidates.all? { |bool| bool == true } true else false end # rubocop:enable Lint/DuplicateBranch end |