Top Level Namespace

Defined Under Namespace

Modules: ActiveRecord, Dao, DaoHelper, Kernel, MongoMapper Classes: APIController, Array, DaoGenerator

Constant Summary collapse

Api =
Dao.api do
##
#
  README <<-__
    this a dao api
    
      so nice

    so good
  __

##
#
  desc '/ping - hello world without a user'
  call('/ping'){
    data.update :time => Time.now
  }

  desc '/pong - hello world with a user'
  call('/pong'){
    require_current_user!
    data.update :time => Time.now
    data.update :current_user => current_user
  }

## 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=')
  alias_method('effective_user?', 'effective_user')
  alias_method('real_user?', 'real_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 real_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
ApiController =

rails is a bitch - shut her up

APIController

Instance Method Summary collapse

Instance Method Details

#ApiObject

mo betta in development



105
# File 'lib/dao/rails/lib/generators/dao/templates/api.rb', line 105

unloadable(Api)

#dirObject

look for any other apis to load



97
98
99
100
101
# File 'lib/dao/rails/lib/generators/dao/templates/api.rb', line 97

%w( api apis ).each do |dir|
  glob = File.expand_path(File.join(Rails.root, "app/#{ dir }/**/*.rb"))
  files = Dir.glob(glob).sort
  files.each{|file| ::Kernel.load(file)}
end

#tap(value, &block) ⇒ Object



13
14
15
16
# File 'lib/dao/stdext.rb', line 13

def tap(value, &block)
  block.call(value)
  value
end