Class: Packwerk::Configuration
- Inherits:
-
Object
- Object
- Packwerk::Configuration
- Defined in:
- lib/packwerk/configuration.rb
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
"packwerk.yml"- DEFAULT_INCLUDE_GLOBS =
["**/*.{rb,rake,erb}"]
- DEFAULT_EXCLUDE_GLOBS =
["{bin,node_modules,script,tmp,vendor}/**/*"]
Instance Attribute Summary collapse
- #associations_exclude ⇒ Object readonly
- #cache_directory ⇒ Object readonly
- #config_path ⇒ Object readonly
- #custom_associations ⇒ Object readonly
- #exclude ⇒ Object readonly
- #include ⇒ Object readonly
- #package_paths ⇒ Object readonly
- #parallel ⇒ Object writeonly
- #root_path ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #cache_enabled? ⇒ Boolean
-
#initialize(configs = {}, config_path: nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #load_paths ⇒ Object
- #offenses_formatter ⇒ Object
- #parallel? ⇒ Boolean
Constructor Details
#initialize(configs = {}, config_path: nil) ⇒ Configuration
Returns a new instance of Configuration.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/packwerk/configuration.rb', line 66 def initialize(configs = {}, config_path: nil) @include = configs["include"] || DEFAULT_INCLUDE_GLOBS #: Array[String] @exclude = configs["exclude"] || DEFAULT_EXCLUDE_GLOBS #: Array[String] root = config_path ? File.dirname(config_path) : "." @root_path = File.(root) #: String @package_paths = configs["package_paths"] || "**/" #: (String | Array[String]) @custom_associations = (configs["custom_associations"] || []).map(&:to_sym) #: Array[Symbol] @associations_exclude = configs["associations_exclude"] || [] #: Array[String] @parallel = configs.key?("parallel") ? configs["parallel"] : true #: bool @cache_enabled = configs.key?("cache") ? configs["cache"] : false #: bool @cache_directory = Pathname.new(configs["cache_directory"] || "tmp/cache/packwerk") #: Pathname @config_path = config_path @offenses_formatter_identifier = configs["offenses_formatter"] || Formatters::DefaultOffensesFormatter::IDENTIFIER #: String if configs.key?("require") configs["require"].each do |require_directive| ExtensionLoader.load(require_directive, @root_path) end end end |
Instance Attribute Details
#associations_exclude ⇒ Object (readonly)
54 55 56 |
# File 'lib/packwerk/configuration.rb', line 54 def associations_exclude @associations_exclude end |
#cache_directory ⇒ Object (readonly)
60 61 62 |
# File 'lib/packwerk/configuration.rb', line 60 def cache_directory @cache_directory end |
#config_path ⇒ Object (readonly)
57 58 59 |
# File 'lib/packwerk/configuration.rb', line 57 def config_path @config_path end |
#custom_associations ⇒ Object (readonly)
51 52 53 |
# File 'lib/packwerk/configuration.rb', line 51 def custom_associations @custom_associations end |
#exclude ⇒ Object (readonly)
42 43 44 |
# File 'lib/packwerk/configuration.rb', line 42 def exclude @exclude end |
#include ⇒ Object (readonly)
39 40 41 |
# File 'lib/packwerk/configuration.rb', line 39 def include @include end |
#package_paths ⇒ Object (readonly)
48 49 50 |
# File 'lib/packwerk/configuration.rb', line 48 def package_paths @package_paths end |
#parallel=(value) ⇒ Object (writeonly)
63 64 65 |
# File 'lib/packwerk/configuration.rb', line 63 def parallel=(value) @parallel = value end |
#root_path ⇒ Object (readonly)
45 46 47 |
# File 'lib/packwerk/configuration.rb', line 45 def root_path @root_path end |
Class Method Details
.from_path(path = Dir.pwd) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/packwerk/configuration.rb', line 11 def from_path(path = Dir.pwd) raise ArgumentError, "#{File.(path)} does not exist" unless File.exist?(path) default_packwerk_path = File.join(path, DEFAULT_CONFIG_PATH) if File.file?(default_packwerk_path) from_packwerk_config(default_packwerk_path) else new end end |
Instance Method Details
#cache_enabled? ⇒ Boolean
104 105 106 |
# File 'lib/packwerk/configuration.rb', line 104 def cache_enabled? @cache_enabled end |
#load_paths ⇒ Object
89 90 91 |
# File 'lib/packwerk/configuration.rb', line 89 def load_paths @load_paths ||= RailsLoadPaths.for(@root_path, environment: "test") #: Hash[String, Module[top]]? end |
#offenses_formatter ⇒ Object
99 100 101 |
# File 'lib/packwerk/configuration.rb', line 99 def offenses_formatter OffensesFormatter.find(@offenses_formatter_identifier) end |
#parallel? ⇒ Boolean
94 95 96 |
# File 'lib/packwerk/configuration.rb', line 94 def parallel? @parallel end |