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

"Rename" target mutation #82

Open
sobolevn opened this issue Feb 7, 2019 · 0 comments
Open

"Rename" target mutation #82

sobolevn opened this issue Feb 7, 2019 · 0 comments

Comments

@sobolevn
Copy link

sobolevn commented Feb 7, 2019

Related to #81

The same problem I have with other attributes in dicts that must be renamed before actually working with them.

def tranform_data(webhook):
    return glom(webhook_data, (
            Assign('project.id', Spec('project.uid')),

            # Issue tranformation:
            Assign('object_attributes.id', Spec('object_attributes.uid')),
            Assign('issue', Spec('object_attributes')),
        ))

And then usage:

webhook_data = {'project': {'uid': 1}, 'object_attributes': {'uid': 2}}
modified = tranform_data(webhook_data)
# =>  {'project': {'id': 1, 'uid': 1}, 'object_attributes': {'id': 2, 'uid': 2}, 'issue': {'id': 2, 'uid': 2}}

That can quickly become to complex inside, when we really want ot just rename the key.
So, that why I suggest to make Rename mutation.

That's how it would work:

def tranform_data(webhook):
    return glom(webhook_data, (
            Rename('project.id', Spec('project.uid')),

            # Issue tranformation:
            Rename('object_attributes.id', Spec('object_attributes.uid')),
            Rename('issue', Spec('object_attributes')),
        ))

webhook_data = {'project': {'uid': 1}, 'object_attributes': {'uid': 2}}
modified = tranform_data(webhook_data)
# =>  {'project': {'id': 1}, 'issue': {'id': 2}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant