Skip to content

Commit

Permalink
#2 allow dynamic keys to not be necessarily sent in array
Browse files Browse the repository at this point in the history
  • Loading branch information
Radagaisus committed Jan 3, 2014
1 parent e7b9da6 commit 36fb2c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/orpheus.coffee
Expand Up @@ -492,9 +492,12 @@ class OrpheusAPI

type = @model[key].type

# generate a new key name, if it has a
# dynamic key function.
# Generate a new key name, if it has a dynamic key function.
if key and @model[key].options.key
# Dynamic keys arguments can be passed in an array, or, if it's just one
# key, as is.
dynamic_key_args = [dynamic_key_args] unless _.isArray(dynamic_key_args)
# Call the model key function with the dynamic key arguments to get the key
key = @model[key].options.key.apply(this, dynamic_key_args)

if type is 'str' or type is 'num'
Expand Down
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -8,12 +8,11 @@
"devDependencies": {
"jasmine-node": "latest",
"metrics": "0.1.6",
"redis": "0.8.2"
"redis": "0.10.0"
},
"dependencies": {
"async": "0.1.22",
"underscore": "1.4.3",
"hooks": "0.2.1"
"underscore": "1.4.3"
},
"bugs": {
"url": "http://github.com/Radagaisus/Orpheus/issues"
Expand Down
16 changes: 16 additions & 0 deletions test/orpheus.spec.coffee
Expand Up @@ -137,6 +137,22 @@ describe 'Redis Commands', ->
expect(res).toBe 'shalom'
done()

it 'Dynamic key arguments, not in array', (done) ->

class Test extends Orpheus
constructor: ->
@str 'something', key: (actual) -> "test:#{actual}"

test = Test.create()

test('hello')
.something.set('Barış', key: 'yeah')
.exec ->
r.hget "#{PREFIX}:te:hello", "test:yeah", (err, res) ->
expect(res).toBe 'Barış'
done()


it 'Num and Str single commands', (done) ->
class Player extends Orpheus
constructor: ->
Expand Down

0 comments on commit 36fb2c5

Please sign in to comment.