mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-02-23 15:49:49 +01:00
refactor(lib): move resource builder into own lib
As the code is likely to grow far more complex, it's required to move it as long as it is easy to do so.
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
<%
|
||||
from util import (iter_nested_types, new_context, rust_comment, rust_doc_comment,
|
||||
rust_module_doc_comment, rust_doc_test_norun, canonical_type_name,
|
||||
mb_type, singular, rust_test_fn_invisible, put_and)
|
||||
rust_module_doc_comment, mb_type, hub_type)
|
||||
nested_schemas = list(iter_nested_types(schemas))
|
||||
|
||||
c = new_context(resources)
|
||||
|
||||
hub_type = canonical_type_name(canonicalName)
|
||||
hub_type = hub_type(canonicalName)
|
||||
|
||||
%>\
|
||||
<%namespace name="lib" file="lib/lib.mako"/>\
|
||||
<%namespace name="mutil" file="lib/util.mako"/>\
|
||||
<%namespace name="util" file="lib/util.mako"/>\
|
||||
<%namespace name="rbuild" file="lib/rbuild.mako"/>\
|
||||
<%namespace name="schema" file="lib/schema.mako"/>\
|
||||
<%block filter="rust_comment">\
|
||||
<%mutil:gen_info source="${self.uri}" />\
|
||||
<%util:gen_info source="${self.uri}" />\
|
||||
</%block>
|
||||
|
||||
<%block filter="rust_module_doc_comment">\
|
||||
@@ -97,33 +97,17 @@ ${schema.new(s, c)}
|
||||
// MethodBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource, methods in c.rta_map.iteritems():
|
||||
/// A builder providing access to all methods supported on *${singular(resource)}* resources.
|
||||
/// It is usually not used directly, but through the `${hub_type}` hub.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Instantiate a resource builder
|
||||
///
|
||||
<%block filter="rust_doc_test_norun, rust_doc_comment">\
|
||||
${mutil.test_prelude()}\
|
||||
% for resource in c.rta_map:
|
||||
${rbuild.new(resource, c)}
|
||||
|
||||
<%block filter="rust_test_fn_invisible">\
|
||||
${lib.test_hub(canonical_type_name(canonicalName))}\
|
||||
|
||||
// Usually you wouldn't stick this into a variable, but keep calling `MethodBuilders`
|
||||
// like ${put_and(sorted('`%s(...)`' % f for f in methods))}
|
||||
let rb = hub.${resource}();
|
||||
</%block>
|
||||
</%block>
|
||||
pub struct ${mb_type(resource)}<'a, C, NC, A>
|
||||
where NC: 'a,
|
||||
C: 'a,
|
||||
A: 'a, {
|
||||
|
||||
hub: &'a ${hub_type}<C, NC, A>
|
||||
}
|
||||
|
||||
impl<'a, C, NC, A> MethodBuilder for ${mb_type(resource)}<'a, C, NC, A> {}
|
||||
% endfor
|
||||
|
||||
|
||||
// ###################
|
||||
// CallBuilders ###
|
||||
// #################
|
||||
|
||||
% for resource in c.rta_map:
|
||||
|
||||
% endfor
|
||||
40
src/mako/lib/rbuild.mako
Normal file
40
src/mako/lib/rbuild.mako
Normal file
@@ -0,0 +1,40 @@
|
||||
<%!
|
||||
from util import (put_and, rust_test_fn_invisible, rust_doc_test_norun, rust_doc_comment,
|
||||
mb_type, singular, hub_type)
|
||||
%>\
|
||||
<%namespace name="util" file="util.mako"/>\
|
||||
<%namespace name="lib" file="lib.mako"/>\
|
||||
|
||||
## Creates a Resource builder type
|
||||
###############################################################################################
|
||||
###############################################################################################
|
||||
<%def name="new(resource, c)">\
|
||||
<% hub_type_name = hub_type(canonicalName) %>
|
||||
/// A builder providing access to all methods supported on *${singular(resource)}* resources.
|
||||
/// It is usually not used directly, but through the `${hub_type_name}` hub.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Instantiate a resource builder
|
||||
///
|
||||
<%block filter="rust_doc_test_norun, rust_doc_comment">\
|
||||
${util.test_prelude()}\
|
||||
|
||||
<%block filter="rust_test_fn_invisible">\
|
||||
${lib.test_hub(hub_type_name)}\
|
||||
|
||||
// Usually you wouldn't stick this into a variable, but keep calling `MethodBuilders`
|
||||
// like ${put_and(sorted('`%s(...)`' % f for f in c.rta_map[resource]))}
|
||||
let rb = hub.${resource}();
|
||||
</%block>
|
||||
</%block>
|
||||
pub struct ${mb_type(resource)}<'a, C, NC, A>
|
||||
where NC: 'a,
|
||||
C: 'a,
|
||||
A: 'a, {
|
||||
|
||||
hub: &'a ${hub_type_name}<C, NC, A>
|
||||
}
|
||||
|
||||
impl<'a, C, NC, A> MethodBuilder for ${mb_type(resource)}<'a, C, NC, A> {}
|
||||
</%def>
|
||||
@@ -313,3 +313,6 @@ def library_name(name, version):
|
||||
# return type name of a resource builder, from a resource name
|
||||
def mb_type(r):
|
||||
return "%sMethodBuilder" % canonical_type_name(r)
|
||||
|
||||
def hub_type(canonicalName):
|
||||
return canonical_type_name(canonicalName)
|
||||
|
||||
Reference in New Issue
Block a user