-
Notifications
You must be signed in to change notification settings - Fork 595
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
Implement Service & ServiceObject classes #904
Implement Service & ServiceObject classes #904
Conversation
this.makeReq_('DELETE', '', query, null, callback); | ||
this.request({ | ||
method: 'DELETE', | ||
uri: '', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
fb15704
to
9a752c2
Compare
@callmehiphop can you take another quick glance over the changes I've made (latest commit)? I think I may have come up with an easier way to handle the We don't override methods just to call them again only for the docs to be built properly. I cheated around that by just documenting aobject that is used when we extend from ServiceObject. Also, the docs are much simpler to avoid all of the replication. The |
I like this approach much more than the previous. However it still kinda feels odd to me, mainly because I don't think we should be adding code for the sake of documentation, even if it's just a little. I think I've suggested this before, but have we considered moving away from dox? JSDoc3 actually has pretty nice support for spitting out plain old JSON (minus custom tags). It also allows you to document "virtual" members, which is just code that exists elsewhere. (e.g. I realize this would be a large undertaking, so this is obviously not the time or place for a change like that, but it's still something I think we should consider. Aside from that, I think it looks good! |
Which code does that? |
I'd be in support of this, but given the scope of the work involved, it's a pretty intimidating task to take on. Maybe switching over should happen when we get to the gcloud-* common docs task. |
Maybe I misunderstood, but I thought the main reason to switch to an object containing method names flagged as |
Yeah totally! |
It does work for that purpose, but it's also to communicate to |
Gotcha! Do you think it would be better to make a custom inherit(BigQuery, ServiceObject, {
getOrCreate: null
}); Either way, I approve! |
RE: the
There definitely might be a better way to do this though, so I'll think about it as I go on. Something worth noting is in some cases, we don't know if a class needs a method or not until it's instantiated. |
Why is that? |
this.name = name; | ||
this.metadata = {}; | ||
function Snapshot(scope, name) { | ||
var isDisk = scope.constructor.name === 'Disk'; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@callmehiphop feel free to take a look at the new implementation of Then... testing. Dun, dun, dun. |
|
||
// The `request` method may have been overridden to hold any special behavior. | ||
// Ensure we call the original `request` method. | ||
ServiceObject.prototype.request.call(this, reqOpts, function(err, resp) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
yay! looks good |
f15c67e
to
59570b9
Compare
This is getting pretty huge, GitHub can't even display the entire diff because of the size. Any chance we could break any of this up? |
Yes, very good idea. I'll start with Service & ServiceObject. |
This PR is going to be split into pieces
Core Service & ServiceObject: #928
BigQuery: #931
Compute: #932
Datastore: #897
DNS: #942
Resource: #943
Pub/Sub: #944
Search: #945
Storage: #946
Fixes #847
Fixes #862
Fixes #914
This will be a big PR, and is still a work in progress. @callmehiphop -- please review at your earliest convenience!
To Dos
Service.serviceObject = function() {}
docs remove "reference an existing ____"create
is shown with a config object where requiredBigQuery.dataset#createTable
: previously(options, callback)
, now(id, options, callback)
Goal
Add
create
,get
(withautoCreate
behavior), andexists
methods to all service objects.Implementation
Distinctly define the types of classes we have:
Define common methods for each:
request
=> make an authenticated requestcreate
=> create this objectexists
=> does this object exist, returns true or falseget
=> get the metadata for this object -- pass{autoCreate:true}
to create the object if it doesn't existdelete
=> delete this objectgetMetadata
=> get the metadata for this objectsetMetadata
=> set the metadata for this objectrequest
=> make an authenticated requestWe've been re-writing these methods all over our library, which has led to some unwanted side effects (inconsistency / repeated code / repeated tests). This separation will allow us to write once, run everywhere.
The Problems
object.delete()
. And we have to uniquely documentcreate
, since each method will take different parameters.