Writing dynamic exposures by overriding initialize

Đang mở
#257 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
api

Hướng nghiên cứu

Start in entity.rb at line 175 and inspect how exposures are appended to root_exposures. Reproduce the duplicate-exposure behavior described in the issue and review the reported test coverage. Done means repeated dynamic exposure initialization no longer degrades performance and regression coverage passes.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

I've got a project that was still running 0.4.8 where, for example, we have Arrival and Departure types of Flight records, and the consumer wanted fields labelled as such. Rather than writing a bunch of boilerplate like:

expose :blah, as: :departure_blah, if: if: lambda {|o,_p| o.type == "Departure" }

I overrode the entity child class's initialize method:

  def initialize(object, options = {})
    if object
      self.class.expose :blah, as: "#{type}_blah"
    end
    super(object, options)
  end

This worked fine but after (finally) upgrading to 0.6.0 this started causing duplicate exposures to be added the root_exposures class variable, steadily degrading performance over time. Changing line 175 of entity.rb to root_exposures << exposure unless root_exposures.include?(exposure) fixes the issue, I've got test coverage written for that but following along the instructions for contributing I just get permission denied errors when attempting to push my branch.

Looking at that old code I realize that was an awful kludgey way of going about it.

Ngôn ngữ chính
Ruby
Star
729
Fork
154
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby-grape/grape-entity

Tất cả issue của ruby-grape/grape-entity

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.