Refactored transform keys to use mutation

Reduces memory since these attributes are safe to mutate since there is no reference to the original object. This also removes use of refinements since this functionality is native to Ruby.

Milestone: patch
This commit is contained in:
Brooke Kuhlmann
2026-07-31 11:36:04 -06:00
parent a541c98e3b
commit f4e43bfd8d
4 changed files with 3 additions and 10 deletions
-3
View File
@@ -2,7 +2,6 @@
require "inspectable"
require "pipeable"
require "refinements/hash"
module TRMNL
module API
@@ -18,8 +17,6 @@ module TRMNL
include Inspectable[schema: :type]
include Pipeable
using Refinements::Hash
def call **parameters
parameters.transform_keys! sort: "sort-by"
+1 -1
View File
@@ -6,7 +6,7 @@ module TRMNL
# Models the data of the API response.
IPAddress = ::Data.define :version_4, :version_6 do
def self.for attributes
new(**attributes.transform_keys(ipv4: :version_4, ipv6: :version_6))
new(**attributes.transform_keys!(ipv4: :version_4, ipv6: :version_6))
end
end
end
+1 -2
View File
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require "core"
require "refinements/hash"
module TRMNL
module API
@@ -24,7 +23,7 @@ module TRMNL
:palette_names,
:css
) do
def self.for(attributes) = new(**attributes.transform_keys(palette_ids: :palette_names))
def self.for(attributes) = new(**attributes.transform_keys!(palette_ids: :palette_names))
def initialize(**)
super
+1 -4
View File
@@ -1,16 +1,13 @@
# frozen_string_literal: true
require "core"
require "refinements/hash"
module TRMNL
module API
module Models
# Models the data of the API response.
Palette = Struct.new :name, :label, :grays, :colors, :framework_class do
using Refinements::Hash
def self.for(attributes) = new(**attributes.transform_keys(name: :label, id: :name))
def self.for(attributes) = new(**attributes.transform_keys!(name: :label, id: :name))
def initialize(**)
super