Class: Dependabot::Swift::FileUpdater::XcodeLockfileUpdater
- Inherits:
-
Object
- Object
- Dependabot::Swift::FileUpdater::XcodeLockfileUpdater
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/swift/file_updater/xcode_lockfile_updater.rb
Constant Summary collapse
- SUPPORTED_VERSIONS =
T.let([1, 2, 3].freeze, T::Array[Integer])
- PIN_KEYS =
Maps schema version to the JSON keys used for each pin field
T.let( { 1 => { url: "repositoryURL", identity: "package", pins_path: %w(object pins) }, 2 => { url: "location", identity: "identity", pins_path: ["pins"] }, 3 => { url: "location", identity: "identity", pins_path: ["pins"] } }.freeze, T::Hash[Integer, T::Hash[Symbol, T.untyped]] )
Instance Method Summary collapse
-
#initialize(resolved_file:, dependencies:, workspace_files: []) ⇒ XcodeLockfileUpdater
constructor
A new instance of XcodeLockfileUpdater.
- #lockfile_changed? ⇒ Boolean
- #updated_lockfile_content ⇒ Object
Constructor Details
#initialize(resolved_file:, dependencies:, workspace_files: []) ⇒ XcodeLockfileUpdater
Returns a new instance of XcodeLockfileUpdater.
39 40 41 42 43 |
# File 'lib/dependabot/swift/file_updater/xcode_lockfile_updater.rb', line 39 def initialize(resolved_file:, dependencies:, workspace_files: []) @resolved_file = resolved_file @dependencies = dependencies @workspace_files = workspace_files end |
Instance Method Details
#lockfile_changed? ⇒ Boolean
75 76 77 |
# File 'lib/dependabot/swift/file_updater/xcode_lockfile_updater.rb', line 75 def lockfile_changed? dependencies_for_file.any? end |
#updated_lockfile_content ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dependabot/swift/file_updater/xcode_lockfile_updater.rb', line 46 def updated_lockfile_content content = resolved_file.content unless content raise Dependabot::DependencyFileNotParseable.new( resolved_file.name, "#{resolved_file.name} has no content" ) end parsed = parse_json(content) schema_version = detect_schema_version(parsed) keys = T.must(PIN_KEYS[schema_version]) update_pins(parsed, schema_version, keys) # Use JSON.pretty_generate to match Xcode's output format: # - 2-space indentation # - space before colon (e.g., "key" : "value") JSON.pretty_generate( parsed, indent: " ", space: " ", space_before: " ", object_nl: "\n", array_nl: "\n" ) + "\n" end |