Skip to content

Commit

Permalink
Update :scope to be coerced into an Array if it is not already
Browse files Browse the repository at this point in the history
* Minor doc/spec update to show this new behaviour
  • Loading branch information
dkubb committed May 19, 2010
1 parent 4c602af commit 86386f6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -57,7 +57,7 @@ having their own todo-lists.
belongs_to :user

# here we define that this should be a list, scoped on :user_id
is :list, :scope => [:user_id]
is :list, :scope => :user_id # you may also pass in multiple properties, eg [ :user_id, :title ]
end

Once we have our Users and Lists, we might want to work with...
Expand Down
9 changes: 6 additions & 3 deletions lib/dm-is-list/is/list.rb
Expand Up @@ -235,9 +235,9 @@ module List
# custom :field
#
# @example [Usage]
# is :list # put this in your model to make it act as a list.
# is :list, :scope => [:user_id] # you can also define scopes
# is :list, :scope => [:user_id, :context_id] # also works with multiple params
# is :list # put this in your model to make it act as a list.
# is :list, :scope => :user_id # you can also define scopes
# is :list, :scope => [ :user_id, :context_id ] # also works with multiple params
#
# @param options <Hash> a hash of options
#
Expand All @@ -247,6 +247,9 @@ module List
def is_list(options={})
options = { :scope => [], :first => 1 }.merge(options)

# coerce the scope into an Array
options[:scope] = Array(options[:scope])

extend DataMapper::Is::List::ClassMethods
include DataMapper::Is::List::InstanceMethods

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -23,7 +23,7 @@ class Todo

belongs_to :user

is :list, :scope => [:user_id]
is :list, :scope => :user_id
end

module TodoListHelper
Expand Down

0 comments on commit 86386f6

Please sign in to comment.