Guest User

Untitled

a guest
May 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. require 'dm-core'
  2.  
  3. DataMapper::Logger.new(STDOUT, :debug)
  4. DataMapper.setup :default,
  5. :adapter => 'postgres',
  6. :host => 'localhost',
  7. :port => 5432,
  8. :username => 'dofus_treasury',
  9. :password => 'dofus_treasury',
  10. :database => 'dofus_treasury'
  11.  
  12.  
  13. # Items are identified by names, for example, Bread
  14. # A recipe has one product item, and a few ingredient items each dosed with a
  15. # quantity, for example, Bread = 2 Flour + 1 Yeast + 1 Water
  16. # A dosage is to used to hold one ingredient item and its quantity
  17.  
  18. class Item
  19. include DataMapper::Resource
  20.  
  21. property :name, String, :key => true
  22. has n, :dosages
  23.  
  24. has n, :producing_recipes, :class_name => 'Recipe',
  25. :child_key => [:product_name]
  26. has n, :consuming_recipes, :class_name => 'Recipe',
  27. :through => :dosages,
  28. :remote_relationship_name => :recipe
  29. has n, :derivatives, :class_name => 'Item',
  30. :through => :consuming_recipes,
  31. :remote_name => :product,
  32. :child_key => [:product_name]
  33. has n, :materials, :class_name => 'Item',
  34. :through => :producing_recipes,
  35. :remote_relationship_name =>
  36. :ingredients,
  37. :child_key => [:product_name]
  38. end
  39.  
  40. class Stack
  41. include DataMapper::Resource
  42. property :id, Serial
  43. property :type, Discriminator
  44. property :quantity, Integer
  45. property :item_name, String
  46.  
  47. belongs_to :item
  48. end
  49.  
  50. class Dosage < Stack
  51. property :recipe_id, Integer
  52. belongs_to :recipe
  53. end
  54.  
  55. class Recipe
  56. include DataMapper::Resource
  57.  
  58. property :id, Serial
  59. belongs_to :product, :class_name => 'Item',
  60. :child_key => [:product_name]
  61. has n, :dosages
  62. has n, :ingredients, :class_name => 'Item',
  63. :through => :dosages,
  64. :remote_relationship_name => :item
  65. end
  66.  
  67. class Identity
  68. include DataMapper::Resource
  69.  
  70. property :url, String, :key => true
  71. has 1, :inventory
  72. has n, :items, :through => :inventory
  73. end
  74.  
  75. class Inventory
  76. include DataMapper::Resource
  77.  
  78. property :id, Serial
  79. has n, :containments
  80. belongs_to :identity
  81. end
  82.  
  83. class Containment < Stack
  84. property :inventory_id, Integer
  85. belongs_to :inventory
  86. end
  87.  
  88. DataMapper.auto_upgrade!
Add Comment
Please, Sign In to add comment