Class: CodeOwnership::Private::ParseJsPackages::Package

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/code_ownership/private/parse_js_packages.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(pathname) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/code_ownership/private/parse_js_packages.rb', line 22

def self.from(pathname)
  package_loaded_json = JSON.parse(pathname.read)

  package_name = if pathname.dirname == Pathname.new('.')
                   ROOT_PACKAGE_NAME
                 else
                   pathname.dirname.cleanpath.to_s
                 end

  new(
    name: package_name,
    metadata: package_loaded_json[METADATA] || {}
  )
rescue JSON::ParserError => e
  error_message = <<~MESSAGE
    #{e.inspect}

    #{pathname} has invalid JSON, so code ownership cannot be determined.

    Please either make the JSON in that file valid or specify `js_package_paths` in config/code_ownership.yml.
  MESSAGE

  raise InvalidCodeOwnershipConfigurationError, error_message
end

Instance Method Details

#directoryObject



48
49
50
51
# File 'lib/code_ownership/private/parse_js_packages.rb', line 48

def directory
  root_pathname = Pathname.new('.')
  name == ROOT_PACKAGE_NAME ? root_pathname.cleanpath : root_pathname.join(name).cleanpath
end