Class: Packwerk::Privacy::Package

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/packwerk/privacy/package.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(package) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/packwerk/privacy/package.rb', line 25

def from(package)
  Package.new(
    public_path: public_path_for(package),
    user_defined_public_path: user_defined_public_path(package),
    enforce_privacy: package.config['enforce_privacy'],
    private_constants: package.config['private_constants'] || [],
    ignored_private_constants: package.config['ignored_private_constants'] || [],
    strict_privacy_ignored_patterns: package.config['strict_privacy_ignored_patterns'] || []
  )
end

.public_path_for(package) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/packwerk/privacy/package.rb', line 45

def public_path_for(package)
  unprefixed_public_path = user_defined_public_path(package) || 'app/public/'

  if package.root?
    unprefixed_public_path
  else
    File.join(package.name, unprefixed_public_path)
  end
end

.user_defined_public_path(package) ⇒ Object



37
38
39
40
41
42
# File 'lib/packwerk/privacy/package.rb', line 37

def user_defined_public_path(package)
  return unless package.config['public_path']
  return package.config['public_path'] if package.config['public_path'].end_with?('/')

  "#{package.config['public_path']}/"
end

Instance Method Details

#public_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/packwerk/privacy/package.rb', line 17

def public_path?(path)
  path.start_with?(public_path)
end