mirror of
https://github.com/usetrmnl/trmnl-api.git
synced 2026-08-13 14:29:56 -07:00
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:
@@ -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"
|
||||
|
||||
|
||||
@@ -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,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,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
|
||||
|
||||
Reference in New Issue
Block a user