Class: Packwerk::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.expand_path(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_excludeObject (readonly)

: Array



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

def associations_exclude
  @associations_exclude
end

#cache_directoryObject (readonly)

: Pathname



60
61
62
# File 'lib/packwerk/configuration.rb', line 60

def cache_directory
  @cache_directory
end

#config_pathObject (readonly)

: String?



57
58
59
# File 'lib/packwerk/configuration.rb', line 57

def config_path
  @config_path
end

#custom_associationsObject (readonly)

: Array



51
52
53
# File 'lib/packwerk/configuration.rb', line 51

def custom_associations
  @custom_associations
end

#excludeObject (readonly)

: Array



42
43
44
# File 'lib/packwerk/configuration.rb', line 42

def exclude
  @exclude
end

#includeObject (readonly)

: Array



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

def include
  @include
end

#package_pathsObject (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_pathObject (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

Raises:

  • (ArgumentError)


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.expand_path(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

Returns:

  • (Boolean)


104
105
106
# File 'lib/packwerk/configuration.rb', line 104

def cache_enabled?
  @cache_enabled
end

#load_pathsObject

: -> 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_formatterObject

: -> OffensesFormatter



99
100
101
# File 'lib/packwerk/configuration.rb', line 99

def offenses_formatter
  OffensesFormatter.find(@offenses_formatter_identifier)
end

#parallel?Boolean

: -> bool

Returns:

  • (Boolean)


94
95
96
# File 'lib/packwerk/configuration.rb', line 94

def parallel?
  @parallel
end