Skip to content

Commit

Permalink
cool new model macro
Browse files Browse the repository at this point in the history
  • Loading branch information
kristianmandrup committed Dec 6, 2011
1 parent 63ee410 commit 8c15e9d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cantango/api_ext/macros.rb
@@ -1,7 +1,7 @@
module CanTango
module Macros
sweet_scope :ns => {:CanTango => 'cantango/api_ext'} do
autoload_modules :Account, :User
autoload_modules :Account, :User, :Clazz
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/cantango/api_ext/macros/clazz.rb
@@ -0,0 +1,15 @@
module CanTango::Macros
module Clazz
def cantango type = nil
# determine if user or account
if !type
(name =~ /.+Account$/) ? tango_account : tango_user
else
tango_account and return if type.to_s == 'account'
tango_user and return if type.to_s == 'user'
raise ArgumentError, "Unable to determine type of class to register; Please specify :user or :account as argument"
end
end
alias_method :cantango_user, :tango_user
end
end

0 comments on commit 8c15e9d

Please sign in to comment.