Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose attribute_aliases as attributes #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.ar_model_associations

def self.expose_class_attributes(subclass)
subclass.class_eval do
model.attribute_names.each do |attr|
(model.attribute_names | model.try(:attribute_aliases)&.keys).each do |attr|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find on this location. Does it make sense to have method that virtual attributes adds that provides this?

I see we have similar code here and ManageIQ/manageiq-api#1278. Perhaps, we could have something in core that extends AR to give us exposed_attribute_names so we can have one place to test that exposed_attribute_names includes virtual attributes, columns, aliased attributes, etc. Perhaps deprecated_attributes are in the same bucket.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrafanie Did you see my comment above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

next if model.private_method_defined?(attr)
next if EXPOSED_ATTR_BLACK_LIST.any? { |rexp| attr =~ rexp }
next if subclass.base_class != self && method_defined?(attr)
Expand Down
1 change: 1 addition & 0 deletions spec/service_models/miq_ae_service_flavor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
expect(@service_flavor.name).to eq("small")
expect(@service_flavor.description).to eq("really small")
expect(@service_flavor.cpus).to eq(1)
expect(@service_flavor.cpu_total_cores).to eq(1)
expect(@service_flavor.memory).to eq(2.gigabytes)
expect(@service_flavor).to be_kind_of(MiqAeMethodService::MiqAeServiceFlavor)
end
Expand Down