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

Allow extending Meta with user-defined behaviour #51

Closed
aflatter opened this issue Apr 6, 2011 · 2 comments
Closed

Allow extending Meta with user-defined behaviour #51

aflatter opened this issue Apr 6, 2011 · 2 comments

Comments

@aflatter
Copy link

aflatter commented Apr 6, 2011

Hey,

My goal was to override encode and decode in order to allow special processing for specific buckets.
A real world example would be something like:

decode = (data) ->
  json = JSON.parse data
  json.id = @key
  json
encode = (data) ->
  delete data.id
  JSON.stringify data

Unfortunately I currently can not provide custom Meta objects currently as they are passed to the Meta constructor anyway. What I do at the moment looks like:

Meta = require 'riak-js/lib/meta'
Meta::encode = (data) ->
  super unless @bucket == 'foo'
  # do something

A nice way to do that would be:

class FooMeta extends Meta
  decode = (data) ->
    # ...

meta = new FooMeta()
db.save 'foo', {hello: 'world'}, meta, (err, res) ->
  # hi

What do you think? :)

@frank06
Copy link

frank06 commented May 2, 2011

I think it's a good idea but I need to closely look into it, and rework some parts.

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

2 participants