Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.48 KB | None | 0 0
  1. # filename: main.rb
  2.  
  3. require 'rubygems'
  4. require 'sinatra'
  5. require 'data_mapper'
  6. require 'yaml'
  7.  
  8.  
  9. config = File.open('config.yaml') { |config_file| YAML.load(config_file) }
  10. config = ENV['STAGE'] == 'production' ? config['production'] : config['development']
  11.  
  12. config['db'] = config['db'].each.inject({}) { |a,(k,v)| a[k.to_sym] = v; a }
  13.  
  14. require 'ap'; ap config['db']
  15. DataMapper.setup(:default, {:adapter  => "redis"}.merge(config['db']))
  16.  
  17. class ReportItem
  18.   include DataMapper::Resource
  19.   property :id, Serial
  20.   property :name, String
  21.   property :task_name, String
  22.   property :completed_at, DateTime
  23. end
  24.  
  25. # show a report item
  26. get '/report_item/:id' do
  27.   @report_item = ReportItem.get(params[:id])
  28.   halt 404 unless @report_item
  29.   erb :report_item
  30. end
  31.  
  32.  
  33. DataMapper.auto_upgrade!
  34.  
  35.  
  36. # Usage:
  37. #
  38. # STAGE=production ruby main.rb
  39. #
  40. # I got this error:
  41. #
  42. # Timeout::Error at /report_item/1
  43. # Timeout::Error
  44. #
  45. #    file: hiredis.rb
  46. #    location: rescue in connect
  47. #    line: 23
  48. # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb in mon_synchronize
  49. #
  50. #    yield
  51. #
  52. # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in block in each
  53. #
  54. #    @hash.each_key { |o| yield(o) }
  55. #
  56. # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in each_key
  57. #
  58. #    @hash.each_key { |o| yield(o) }
  59. #
  60. # /home/alem0lars/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/set.rb in each
  61. #
  62. #    @hash.each_key { |o| yield(o) }
  63. #
  64. # main.rb in block in <main>
  65. #
  66. #    @report_item = ReportItem.get(params[:id])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement