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 =
: Array
["**/*.{rb,rake,erb}"]
- DEFAULT_EXCLUDE_GLOBS =
: Array
["{bin,node_modules,script,tmp,vendor}/**/*"]
Instance Attribute Summary collapse
-
#associations_exclude ⇒ Object
readonly
: Array.
-
#cache_directory ⇒ Object
readonly
: Pathname.
-
#config_path ⇒ Object
readonly
: String?.
-
#custom_associations ⇒ Object
readonly
: Array.
-
#exclude ⇒ Object
readonly
: Array.
-
#include ⇒ Object
readonly
: Array.
-
#package_paths ⇒ Object
readonly
: (String | Array).
-
#parallel ⇒ Object
writeonly
: bool.
-
#root_path ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.from_path(path = Dir.pwd) ⇒ Object
: (?String path) -> Configuration.
Instance Method Summary collapse
-
#cache_enabled? ⇒ Boolean
: -> bool.
-
#initialize(configs = {}, config_path: nil) ⇒ Configuration
constructor
: (?Hash[String, untyped] configs, ?config_path: String?) -> void.
-
#load_paths ⇒ Object
: -> Hash[String, Module].
-
#offenses_formatter ⇒ Object
: -> OffensesFormatter.
-
#parallel? ⇒ Boolean
: -> bool.
Constructor Details
#initialize(configs = {}, config_path: nil) ⇒ Configuration
: (?Hash[String, untyped] configs, ?config_path: String?) -> void
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)
: Array
54 55 56 |
# File 'lib/packwerk/configuration.rb', line 54 def associations_exclude @associations_exclude end |
#cache_directory ⇒ Object (readonly)
: Pathname
60 61 62 |
# File 'lib/packwerk/configuration.rb', line 60 def cache_directory @cache_directory end |
#config_path ⇒ Object (readonly)
: String?
57 58 59 |
# File 'lib/packwerk/configuration.rb', line 57 def config_path @config_path end |
#custom_associations ⇒ Object (readonly)
: Array
51 52 53 |
# File 'lib/packwerk/configuration.rb', line 51 def custom_associations @custom_associations end |
#exclude ⇒ Object (readonly)
: Array
42 43 44 |
# File 'lib/packwerk/configuration.rb', line 42 def exclude @exclude end |
#include ⇒ Object (readonly)
: Array
39 40 41 |
# File 'lib/packwerk/configuration.rb', line 39 def include @include end |
#package_paths ⇒ Object (readonly)
: (String | Array)
48 49 50 |
# File 'lib/packwerk/configuration.rb', line 48 def package_paths @package_paths end |
#parallel=(value) ⇒ Object (writeonly)
: bool
63 64 65 |
# File 'lib/packwerk/configuration.rb', line 63 def parallel=(value) @parallel = value end |
#root_path ⇒ Object (readonly)
: String
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
: (?String path) -> Configuration
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
: -> bool
104 105 106 |
# File 'lib/packwerk/configuration.rb', line 104 def cache_enabled? @cache_enabled end |
#load_paths ⇒ Object
: -> Hash[String, Module]
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
: -> OffensesFormatter
99 100 101 |
# File 'lib/packwerk/configuration.rb', line 99 def offenses_formatter OffensesFormatter.find(@offenses_formatter_identifier) end |
#parallel? ⇒ Boolean
: -> bool
94 95 96 |
# File 'lib/packwerk/configuration.rb', line 94 def parallel? @parallel end |