-
Notifications
You must be signed in to change notification settings - Fork 26
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
[WIP] Adding support for subcollections and related subresources #61
[WIP] Adding support for subcollections and related subresources #61
Conversation
|
75e8f0f
to
5f2ddc8
Compare
7954eb1
to
8a554b9
Compare
@Fryguy subcollection support + lotsa tests added |
c23fa2f
to
d9d208c
Compare
ping @Fryguy for review, will be needed shortly for Automate work. Thanks. |
|
||
ACTIONS_RETURNING_RESOURCES = %w(create query).freeze | ||
|
||
def exec_action(name, *args, &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should any of these be private?
@@ -0,0 +1,50 @@ | |||
module CollectionActionMixin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be namespaced
@@ -0,0 +1,95 @@ | |||
module QueryableMixin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs namespace
@@ -0,0 +1,24 @@ | |||
module ResourceActionMixin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
const_get(name, false) | ||
else | ||
const_set(name, Class.new(self)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like there is a lot of duplication with collection.
d9d208c
to
b98cf9d
Compare
- Dynamically driven by the "subcollections" exposed via OPTIONS /api/:collection - supports queries and actions Queries: miq.vms.find(166).tags.collect(&:name) miq.vms.find(166).tags.select(:categorization).collect(&:categorization) Subcollection Actions: miq.vms.find(166).tags.assign(:name => "/managed/location/ny") miq.vms.find(166).tags.assign([{:name => "/managed/location/chicago"}, {:name => "/managed/cc/001"}]) Subcollection resource actions: miq.vms.find(166).tags.find(32).unassign miq.vms.find(166).tags.where(:name => "/managed/location/*").collect(&:unassign) Fixes: ManageIQ#31 Fixes: ManageIQ#32
- Moving action specific action methods for resources and subresources to seperate mixin. - Moving action specific action methods for collections and subcollections to seperate mixin. - Moving common queryable methods for collections and subcollections to a common QueryableMixin
- Updated options response fixture to include subcollections - Added collection rspecs - Added resource rspecs
- Add tests for subcollections
- Adding resource actions_vms.json - Adding subcollection actions_vm_tags.json
- Adding tests for subresources
moved to the common collection mixin
b98cf9d
to
f2c4814
Compare
@@ -1,4 +1,4 @@ | |||
module ActionMixin | |||
module ManageIQ::API::ActionMixin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be ManageIQ::API::Client::ActionMixin? Otherwise it might collide with some future mixin in ManageIQ itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point 👍 will update all.
end | ||
|
||
def filters_from_query_relation(condition, option) | ||
filters = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there's a way to turn this into a simpler .collect
if option.kind_of?(Array) | ||
option.each_with_object({}) { |name, hash| hash[name] = "asc" } | ||
else | ||
option.dup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this dup for if you're going to loop over it anyway?
parameters_from_query_relation, filters_from_query_relation and order_parameters_from_query_relation which really live in the mixins/queryable_mixin.rb
option.each_with_object({}) { |name, hash| hash[name] = "asc" } | ||
else | ||
option | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you can remove this completely if you just deal with defaulting nil values below.
[1] pry(main)> option = {"a" => "asc", "b" => "desc"}
[2] pry(main)> option.each {|k, v| puts "#{k} => #{v || "asc"}"}
a => asc
b => desc
[3] pry(main)> option = ["a", "b"]
[4] pry(main)> option.each {|k, v| puts "#{k} => #{v || "asc"}"}
a => asc
b => asc
res_sort_by << sort_attr | ||
sort_order = | ||
case sort_order | ||
when /^asc/i then "asc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this could be when /^asc/i, nil then "asc"
@abellotti This is a lot to digest |
Marked as WIP, I need to revisit Subresource (/api/providers/1/vms/133 vs just /api/vms/133) |
Agreed, getting slowly morphed/simplified as https://github.com/abellotti/manageiq-api-client/tree/enhanced_subcollection_support. will create new PR when in good shape. By simply
|
closing in preference of #80 |
Dynamically driven by the "subcollections" exposed via OPTIONS /api/:collection
supports queries and actions
Queries:
miq.vms.find(166).tags.collect(&:name)
miq.vms.find(166).tags.select(:categorization).collect(&:categorization)
Subcollection Actions:
miq.vms.find(166).tags.assign(:name => "/managed/location/ny")
miq.vms.find(166).tags.assign([{:name => "/managed/location/chicago"}, {:name => "/managed/cc/001"}])
Subcollection resource actions:
miq.vms.find(166).tags.find(32).unassign
miq.vms.find(166).tags.where(:name => "/managed/location/*").collect(&:unassign)
Fixes: #31
Fixes: #32