An open source, stand-alone, customisable public spending data web app.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

116 rindas
3.2 KiB

  1. require 'rubygems'
  2. require 'dm-core'
  3. require 'dm-validations'
  4. require 'dm-timestamps'
  5. require 'dm-aggregates'
  6. require 'dm-serializer'
  7. require 'dm-migrations'
  8. SITE_URL = 'http://armchairauditor.co.uk/'
  9. class Payment
  10. include DataMapper::Resource
  11. property :id, Serial
  12. property :created_at, DateTime
  13. property :updated_at, DateTime
  14. property :service_id, Integer, :required => true
  15. property :supplier_id, Integer, :required => true
  16. property :amount, BigDecimal, :precision => 10, :scale => 2, :required => true # ex VAT
  17. property :d, Date, :required => true # "Updated" in RBWM CSV files
  18. belongs_to :service
  19. belongs_to :supplier
  20. has 1, :directorate, { :through => :service }
  21. def url
  22. SITE_URL + "payments/" + @id.to_s
  23. end
  24. end
  25. class Directorate
  26. include DataMapper::Resource
  27. property :id, Serial
  28. property :created_at, DateTime
  29. property :updated_at, DateTime
  30. property :name, String, :length => 255, :required => true
  31. property :slug, String, :length => 255
  32. has n, :services, :order => ['name']
  33. has n, :suppliers, { :through => :services, :order => ['name'] }
  34. before :save, :slugify
  35. def slugify
  36. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  37. end
  38. end
  39. class Service
  40. include DataMapper::Resource
  41. property :id, Serial
  42. property :created_at, DateTime
  43. property :updated_at, DateTime
  44. property :directorate_id, Integer, :required => true
  45. property :name, String, :length => 255, :required => true
  46. property :slug, String, :length => 255
  47. has n, :payments, :order => ['d']
  48. has n, :suppliers, { :through => :payments, :order => ['name'] }
  49. belongs_to :directorate
  50. before :save, :slugify
  51. def slugify
  52. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  53. end
  54. end
  55. class Supplier
  56. include DataMapper::Resource
  57. property :id, Serial
  58. property :created_at, DateTime
  59. property :updated_at, DateTime
  60. property :name, String, :length => 255, :required => true
  61. property :slug, String, :length => 255
  62. has n, :payments, :order => ['d']
  63. has n, :services, { :through => :payments, :order => ['name'] }
  64. has n, :directorates, { :through => :payments }
  65. before :save, :slugify
  66. def slugify
  67. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  68. end
  69. end
  70. class Council
  71. include DataMapper::Resource
  72. property :id, Serial
  73. property :created_at, DateTime
  74. property :updated_at, DateTime
  75. property :name, String, :length => 255, :required => true
  76. property :slug, String, :length => 255
  77. property :url, String, :length => 255
  78. property :data_url, String, :length => 512
  79. property :open_licence, Boolean, :default => false
  80. property :machine_readable, Boolean, :default => false
  81. property :start_d, Date
  82. property :end_d, Date
  83. before :save, :slugify
  84. def slugify
  85. @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase
  86. end
  87. end
  88. DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3")
  89. DataMapper.auto_upgrade!