An open source, stand-alone, customisable public spending data web app.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

92 řádky
2.4 KiB

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