Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # filename: main.rb
- require 'rubygems'
- require 'sinatra'
- require 'data_mapper'
- require 'yaml'
- config = File.open('config.yaml') { |config_file| YAML.load(config_file) }
- config = ENV['STAGE'] == 'production' ? config['production'] : config['development']
- config['db'] = config['db'].each.inject({}) { |a,(k,v)| a[k.to_sym] = v; a }
- require 'ap'; ap config['db']
- DataMapper.setup(:default, {:adapter => "redis"}.merge(config['db']))
- class ReportItem
- include DataMapper::Resource
- property :id, Serial
- property :name, String
- property :task_name, String
- property :completed_at, DateTime
- end
- # show a report item
- get '/report_item/:id' do
- @report_item = ReportItem.get(params[:id])
- halt 404 unless @report_item
- erb :report_item
- end
- DataMapper.auto_upgrade!
- # Usage:
- #
- # STAGE=production ruby main.rb
- #
- # I got this error:
- #
- # Timeout::Error at /report_item/1
- # Timeout::Error
- #
- # file: hiredis.rb
- # location: rescue in connect
- # line: 23
- # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb in mon_synchronize
- #
- # yield
- #
- # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in block in each
- #
- # @hash.each_key { |o| yield(o) }
- #
- # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in each_key
- #
- # @hash.each_key { |o| yield(o) }
- #
- # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in each
- #
- # @hash.each_key { |o| yield(o) }
- #
- # main.rb in block in <main>
- #
- # @report_item = ReportItem.get(params[:id])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement