Sha256: 06ddfdcd7efd80742f930c4d6a397537dc092c49edd87880ca36ffa6e39897f6
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 KB
Contents
Api = Dao.api do ## # README <<-__ this a dao api so nice so good __ ## # doc '/ping - hello world without a user' call('/ping'){ data.update :time => Time.now } doc '/pong - hello world with a user' call('/pong'){ require_current_user! data.update :time => Time.now data.update :current_user => current_user.id } ## this is simply a suggested way to model your api. it is not required. # attr_accessor :effective_user attr_accessor :real_user def initialize(*args) options = args.extract_options!.to_options! effective_user = args.shift || options[:effective_user] || options[:user] real_user = args.shift || options[:real_user] || effective_user @effective_user = user_for(effective_user) if effective_user @real_user = user_for(real_user) if real_user @real_user ||= @effective_user end ## no doubt you'll want to customize this! # def user_for(arg) User.respond_to?(:for) ? User.for(arg) : User.find(arg) end alias_method('user', 'effective_user') alias_method('user=', 'effective_user=') alias_method('current_user', 'effective_user') alias_method('current_user=', 'effective_user=') def api self end def logged_in? @effective_user and @real_user end def user? logged_in? end def current_user effective_user end def current_user? !!effective_user end def require_effective_user! unless effective_user? status :unauthorized return! end end def require_real_user! unless effective_user? status :unauthorized return! end end def require_current_user! require_effective_user! and require_real_user! end alias_method('require_user!', 'require_current_user!') end unloadable(Api) def api(*args, &block) Api.new(*args, &block) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dao-3.3.0 | lib/dao/rails/lib/generators/dao/templates/api.rb |