Use ActiveModel::Attributes in Aws::Record
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách lần theo các macro thuộc tính của Aws::Record’s BaseModel và các component ModelAttributes và ItemData được nêu trong issue. Xem xét cách các trường được lưu trữ, metadata của DynamoDB, decorator, giá trị mặc định và cơ chế theo dõi thay đổi hiện đang tương tác với nhau. Được xem là hoàn tất khi các decorator của ActiveModel có thể quan sát mọi trường được lưu trữ mà không làm hỏng mapping và hành vi persistence hiện có của DynamoDB.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the feature
Rework Aws::Record’s attribute layer so every attribute is registered through ActiveModel::Attributes. Under this approach, string_attr, integer_attr, etc. would become thin wrappers around attribute(name, type, default:), allowing decorators like ActiveModel::Attributes::Normalization#normalizes to hook into Aws::Record models.
Beyond normalization, this change would:
- Enable all current and future ActiveModel decorators (encryption, serialization helpers, etc.) on Aws::Record fields.
- Improve compatibility with form builders and other ActiveModel-based tools because casting, defaults, and dirty tracking come from the canonical Rails implementation.
- Reduce custom infrastructure—bug fixes and improvements in ActiveModel automatically flow to Aws::Record users instead of maintaining a parallel attribute system.
- Provide cleaner extension points: developers can register custom ActiveModel::Types or third-party decorators without fighting the DynamoDB marshaler layer.
- Simplify the codebase by letting ActiveModel::AttributeSet/ActiveModel::Dirty handle state tracking, trimming down ModelAttributes and ItemData.
Use Case
We attempted to use the new normalizes macro in our case for email addresses in an Aws::Record-backed app:
class Contact
include ActiveModel::Model
include ActiveModel::Attributes
include Aws::Record
include ActiveModel::Attributes::Normalization
string_attr :email
normalizes :email, with: -> value { value&.strip&.downcase }
end
That doesnt work.
Because every persisted field in BaseModel is declared with the Aws::Record macros (string_attr, integer_attr, etc.), the ActiveModel decorator hooks never see read/write operations, so normalization callbacks don’t fire. To make normalizes effective we’d have to redefine every attribute twice (attribute :foo for ActiveModel, plus string_attr :foo for Aws::Record) or build a bridge layer that makes Aws::Record emit the decorators ActiveModel expects. Both approaches would be fragile and risk the DynamoDB mapping getting out of sync. In short: adding include ActiveModel::Attributes to BaseModel won’t crash immediately, but it also doesn’t give us working normalization for the attributes we actually persist.
So we must maintain custom concerns instead of relying on the Rails-provided API.
Proposed Solution
Integrate ActiveModel::Attributes into Aws::Record’s core:
- Mix ActiveModel::Attributes into Aws::Record.
- Update attribute macros to call attribute(name, type, default:), wrapping existing DynamoDB marshalers in ActiveModel::Type subclasses.
- Preserve Dynamo-specific metadata (hash/range keys, GSIs, custom storage names) in side tables so persistence logic remains intact.
- Allow decorate_attributes to run on every field, unlocking normalization and other decorators.
- Refactor ModelAttributes/ItemData to lean on ActiveModel::AttributeSet and ActiveModel::Dirty for defaults and mutation tracking.
Prototype sketch:
class DynamoStringType < ActiveModel::Type::String
def serialize(value)
Aws::Record::Marshalers::StringMarshaler.new.serialize(value)
end
end
def string_attr(name, default: nil, **opts)
register_dynamo_metadata(name, opts)
attribute(name, DynamoStringType.new, default: default)
end
Other Information
No response
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
aws-sdk-ruby-record version used
latest
Environment details (OS name and version, etc.)
mac
- Ngôn ngữ chính
- Ruby
- Star
- 318
- Fork
- 44
- Merge trung bình
- 2 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/aws-record-ruby
-
BuildableSearch#complete!.to_a auto-paginates silently and Limit is per-page (companion to #153)Đang mởfeature-request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
aws/aws-record-ruby#157 · 2 bình luận ·
-
feature-request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
aws/aws-record-ruby#155 · 1 bình luận ·
-
feature-request p2 queued
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
aws/aws-record-ruby#153 · 2 bình luận ·
-
feature-request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
aws/aws-record-ruby#147 · 1 bình luận ·
-
feature-request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
aws/aws-record-ruby#142 · 6 bình luận ·
Tất cả issue của aws/aws-record-ruby
Issue tương tự
-
message-patterns
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
sisimai/rb-sisimai#468 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 7 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 7 ngày
-
NoMethodError in auth#createĐang mởbugsnag
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
JoeMcB/improvcoaches#827 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
TheOdinProject/curriculum#31465 ·
Maintainer thường phản hồi trong vòng 1 ngày