tripper 0.0.3d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/TODO +26 -0
  8. data/lib/generators/USAGE +8 -0
  9. data/lib/generators/tripper.rb +51 -0
  10. data/lib/generators/tripper/commonalities/commonalities.rb +226 -0
  11. data/lib/generators/tripper/detect_changes/detect_changes_generator.rb +173 -0
  12. data/lib/generators/tripper/detect_changes/model.rb +226 -0
  13. data/lib/generators/tripper/detect_changes/templates/migration.rb +7 -0
  14. data/lib/generators/tripper/detect_changes/templates/model/belongs_to.rb +1 -0
  15. data/lib/generators/tripper/detect_changes/templates/model/has_one.rb +1 -0
  16. data/lib/generators/tripper/detect_changes/templates/model/validates.rb +2 -0
  17. data/lib/generators/tripper/from_community/from_community_generator.rb +95 -0
  18. data/lib/generators/tripper/from_community/templates/actions/create.rb +8 -0
  19. data/lib/generators/tripper/from_community/templates/actions/destroy.rb +5 -0
  20. data/lib/generators/tripper/from_community/templates/actions/edit.rb +3 -0
  21. data/lib/generators/tripper/from_community/templates/actions/index.rb +3 -0
  22. data/lib/generators/tripper/from_community/templates/actions/new.rb +3 -0
  23. data/lib/generators/tripper/from_community/templates/actions/show.rb +3 -0
  24. data/lib/generators/tripper/from_community/templates/actions/update.rb +8 -0
  25. data/lib/generators/tripper/from_community/templates/controller.rb +3 -0
  26. data/lib/generators/tripper/from_community/templates/fixtures.yml +9 -0
  27. data/lib/generators/tripper/from_community/templates/helper.rb +2 -0
  28. data/lib/generators/tripper/from_community/templates/migration.rb +30 -0
  29. data/lib/generators/tripper/from_community/templates/model.rb +54 -0
  30. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/create.rb +11 -0
  31. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/destroy.rb +6 -0
  32. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/edit.rb +4 -0
  33. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/index.rb +4 -0
  34. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/new.rb +4 -0
  35. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/show.rb +4 -0
  36. data/lib/generators/tripper/from_community/templates/tests/rspec/actions/update.rb +11 -0
  37. data/lib/generators/tripper/from_community/templates/tests/rspec/controller.rb +8 -0
  38. data/lib/generators/tripper/from_community/templates/tests/rspec/model.rb +7 -0
  39. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/create.rb +13 -0
  40. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/destroy.rb +8 -0
  41. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/edit.rb +6 -0
  42. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/index.rb +6 -0
  43. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/new.rb +6 -0
  44. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/show.rb +6 -0
  45. data/lib/generators/tripper/from_community/templates/tests/shoulda/actions/update.rb +13 -0
  46. data/lib/generators/tripper/from_community/templates/tests/shoulda/controller.rb +5 -0
  47. data/lib/generators/tripper/from_community/templates/tests/shoulda/model.rb +7 -0
  48. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/create.rb +11 -0
  49. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/destroy.rb +6 -0
  50. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/edit.rb +4 -0
  51. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/index.rb +4 -0
  52. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/new.rb +4 -0
  53. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/show.rb +4 -0
  54. data/lib/generators/tripper/from_community/templates/tests/testunit/actions/update.rb +11 -0
  55. data/lib/generators/tripper/from_community/templates/tests/testunit/controller.rb +5 -0
  56. data/lib/generators/tripper/from_community/templates/tests/testunit/model.rb +7 -0
  57. data/lib/generators/tripper/from_community/templates/views/erb/_form.html.erb +16 -0
  58. data/lib/generators/tripper/from_community/templates/views/erb/edit.html.erb +14 -0
  59. data/lib/generators/tripper/from_community/templates/views/erb/index.html.erb +29 -0
  60. data/lib/generators/tripper/from_community/templates/views/erb/new.html.erb +7 -0
  61. data/lib/generators/tripper/from_community/templates/views/erb/show.html.erb +25 -0
  62. data/lib/generators/tripper/from_community/templates/views/haml/_form.html.haml +9 -0
  63. data/lib/generators/tripper/from_community/templates/views/haml/edit.html.haml +14 -0
  64. data/lib/generators/tripper/from_community/templates/views/haml/index.html.haml +25 -0
  65. data/lib/generators/tripper/from_community/templates/views/haml/new.html.haml +7 -0
  66. data/lib/generators/tripper/from_community/templates/views/haml/show.html.haml +20 -0
  67. data/lib/generators/tripper/layout/USAGE +18 -0
  68. data/lib/generators/tripper/layout/layout_generator.rb +29 -0
  69. data/lib/generators/tripper/layout/templates/error_messages_helper.rb +23 -0
  70. data/lib/generators/tripper/layout/templates/layout.html.erb +19 -0
  71. data/lib/generators/tripper/layout/templates/layout.html.haml +21 -0
  72. data/lib/generators/tripper/layout/templates/layout_helper.rb +22 -0
  73. data/lib/generators/tripper/layout/templates/stylesheet.css +83 -0
  74. data/lib/generators/tripper/layout/templates/stylesheet.sass +73 -0
  75. data/lib/generators/tripper/obj_constraint.rb +23 -0
  76. data/lib/generators/tripper/predicate.rb +12 -0
  77. data/lib/generators/tripper/sync_with_community/model.rb +260 -0
  78. data/lib/generators/tripper/sync_with_community/sync_with_community_generator.rb +310 -0
  79. data/lib/generators/tripper/sync_with_community/templates/migration.rb +7 -0
  80. data/lib/generators/tripper/sync_with_community/templates/model/belongs_to.rb +1 -0
  81. data/lib/generators/tripper/sync_with_community/templates/model/has_one.rb +1 -0
  82. data/lib/generators/tripper/sync_with_community/templates/model/validates.rb +2 -0
  83. data/lib/generators/tripper/templates/actions/create.rb +8 -0
  84. data/lib/generators/tripper/templates/actions/destroy.rb +5 -0
  85. data/lib/generators/tripper/templates/actions/edit.rb +3 -0
  86. data/lib/generators/tripper/templates/actions/index.rb +3 -0
  87. data/lib/generators/tripper/templates/actions/new.rb +3 -0
  88. data/lib/generators/tripper/templates/actions/show.rb +3 -0
  89. data/lib/generators/tripper/templates/actions/update.rb +8 -0
  90. data/lib/generators/tripper/templates/controller.rb +3 -0
  91. data/lib/generators/tripper/templates/fixtures.yml +9 -0
  92. data/lib/generators/tripper/templates/helper.rb +2 -0
  93. data/lib/generators/tripper/templates/migration.rb +30 -0
  94. data/lib/generators/tripper/templates/model.rb +54 -0
  95. data/lib/generators/tripper/templates/tests/rspec/actions/create.rb +11 -0
  96. data/lib/generators/tripper/templates/tests/rspec/actions/destroy.rb +6 -0
  97. data/lib/generators/tripper/templates/tests/rspec/actions/edit.rb +4 -0
  98. data/lib/generators/tripper/templates/tests/rspec/actions/index.rb +4 -0
  99. data/lib/generators/tripper/templates/tests/rspec/actions/new.rb +4 -0
  100. data/lib/generators/tripper/templates/tests/rspec/actions/show.rb +4 -0
  101. data/lib/generators/tripper/templates/tests/rspec/actions/update.rb +11 -0
  102. data/lib/generators/tripper/templates/tests/rspec/controller.rb +8 -0
  103. data/lib/generators/tripper/templates/tests/rspec/model.rb +7 -0
  104. data/lib/generators/tripper/templates/tests/shoulda/actions/create.rb +13 -0
  105. data/lib/generators/tripper/templates/tests/shoulda/actions/destroy.rb +8 -0
  106. data/lib/generators/tripper/templates/tests/shoulda/actions/edit.rb +6 -0
  107. data/lib/generators/tripper/templates/tests/shoulda/actions/index.rb +6 -0
  108. data/lib/generators/tripper/templates/tests/shoulda/actions/new.rb +6 -0
  109. data/lib/generators/tripper/templates/tests/shoulda/actions/show.rb +6 -0
  110. data/lib/generators/tripper/templates/tests/shoulda/actions/update.rb +13 -0
  111. data/lib/generators/tripper/templates/tests/shoulda/controller.rb +5 -0
  112. data/lib/generators/tripper/templates/tests/shoulda/model.rb +7 -0
  113. data/lib/generators/tripper/templates/tests/testunit/actions/create.rb +11 -0
  114. data/lib/generators/tripper/templates/tests/testunit/actions/destroy.rb +6 -0
  115. data/lib/generators/tripper/templates/tests/testunit/actions/edit.rb +4 -0
  116. data/lib/generators/tripper/templates/tests/testunit/actions/index.rb +4 -0
  117. data/lib/generators/tripper/templates/tests/testunit/actions/new.rb +4 -0
  118. data/lib/generators/tripper/templates/tests/testunit/actions/show.rb +4 -0
  119. data/lib/generators/tripper/templates/tests/testunit/actions/update.rb +11 -0
  120. data/lib/generators/tripper/templates/tests/testunit/controller.rb +5 -0
  121. data/lib/generators/tripper/templates/tests/testunit/model.rb +7 -0
  122. data/lib/generators/tripper/templates/views/erb/_form.html.erb +16 -0
  123. data/lib/generators/tripper/templates/views/erb/edit.html.erb +14 -0
  124. data/lib/generators/tripper/templates/views/erb/index.html.erb +29 -0
  125. data/lib/generators/tripper/templates/views/erb/new.html.erb +7 -0
  126. data/lib/generators/tripper/templates/views/erb/show.html.erb +25 -0
  127. data/lib/generators/tripper/templates/views/haml/_form.html.haml +9 -0
  128. data/lib/generators/tripper/templates/views/haml/edit.html.haml +14 -0
  129. data/lib/generators/tripper/templates/views/haml/index.html.haml +25 -0
  130. data/lib/generators/tripper/templates/views/haml/new.html.haml +7 -0
  131. data/lib/generators/tripper/templates/views/haml/show.html.haml +20 -0
  132. data/lib/tripper.rb +1 -0
  133. data/lib/tripper/GOSPLDB/config/database.yml +6 -0
  134. data/lib/tripper/GOSPLDB/config_db.rb +9 -0
  135. data/lib/tripper/GOSPLDB/console +2 -0
  136. data/lib/tripper/GOSPLDB/gospl_db_classes.rb +343 -0
  137. data/lib/tripper/GOSPLDB/play_around.rb +4 -0
  138. data/lib/tripper/GOSPLDB/rakefile.rb +88 -0
  139. data/lib/tripper/GOSPLDBToORMDB/gospl_db_to_orm_db.rb +88 -0
  140. data/lib/tripper/ORMDB/config/database.yml +6 -0
  141. data/lib/tripper/ORMDB/config_db.rb +9 -0
  142. data/lib/tripper/ORMDB/console +2 -0
  143. data/lib/tripper/ORMDB/db/migrations/0_create_orm_object_table.rb +17 -0
  144. data/lib/tripper/ORMDB/db/migrations/10_create_no_lot_constraint_table.rb +17 -0
  145. data/lib/tripper/ORMDB/db/migrations/11_create_value_constraint_table.rb +14 -0
  146. data/lib/tripper/ORMDB/db/migrations/12_create_value_constraint_value_table.rb +16 -0
  147. data/lib/tripper/ORMDB/db/migrations/13_create_value_range_table.rb +15 -0
  148. data/lib/tripper/ORMDB/db/migrations/14_create_frequency_constraint_table.rb +16 -0
  149. data/lib/tripper/ORMDB/db/migrations/15_create_value_table.rb +15 -0
  150. data/lib/tripper/ORMDB/db/migrations/16_create_ring_constraint_table.rb +14 -0
  151. data/lib/tripper/ORMDB/db/migrations/17_create_orm_schema_table.rb +21 -0
  152. data/lib/tripper/ORMDB/db/migrations/18_create_uniqueness_constraint_table.rb +15 -0
  153. data/lib/tripper/ORMDB/db/migrations/1_create_no_lot_table.rb +18 -0
  154. data/lib/tripper/ORMDB/db/migrations/2_create_lot_table.rb +18 -0
  155. data/lib/tripper/ORMDB/db/migrations/3_create_object_role_table.rb +18 -0
  156. data/lib/tripper/ORMDB/db/migrations/4_create_reference_table.rb +17 -0
  157. data/lib/tripper/ORMDB/db/migrations/5_create_predicate_table.rb +18 -0
  158. data/lib/tripper/ORMDB/db/migrations/6_create_object_role_constraint_table.rb +18 -0
  159. data/lib/tripper/ORMDB/db/migrations/7_create_subtype_table.rb +17 -0
  160. data/lib/tripper/ORMDB/db/migrations/8_create_mandatory_constraint_table.rb +15 -0
  161. data/lib/tripper/ORMDB/db/migrations/9_create_constraint_table.rb +15 -0
  162. data/lib/tripper/ORMDB/db/orm_ml.sqlite3 +0 -0
  163. data/lib/tripper/ORMDB/db/orm_ml.sqlite3.backup +0 -0
  164. data/lib/tripper/ORMDB/db/orm_ml.sqlite3.juli28-2013 +0 -0
  165. data/lib/tripper/ORMDB/db/orm_ml.sqlite3.old +0 -0
  166. data/lib/tripper/ORMDB/db/schema.rb +58 -0
  167. data/lib/tripper/ORMDB/erd.pdf +0 -0
  168. data/lib/tripper/ORMDB/migrate_db.rb +21 -0
  169. data/lib/tripper/ORMDB/orm_db_classes.rb +423 -0
  170. data/lib/tripper/ORMDB/populate.rb +4 -0
  171. data/lib/tripper/ORMDB/rakefile.rb +88 -0
  172. data/lib/tripper/model_parsers/attribute_parser/AttributeParser.g +50 -0
  173. data/lib/tripper/model_parsers/attribute_parser/AttributeParser.tokens +13 -0
  174. data/lib/tripper/model_parsers/attribute_parser/AttributeParserLexer.rb +538 -0
  175. data/lib/tripper/model_parsers/attribute_parser/AttributeParserParser.rb +412 -0
  176. data/lib/tripper/model_parsers/attribute_parser/playing_around.rb +14 -0
  177. data/lib/tripper/model_parsers/belongs_to/BelongsToParser.g +63 -0
  178. data/lib/tripper/model_parsers/belongs_to/BelongsToParser.tokens +21 -0
  179. data/lib/tripper/model_parsers/belongs_to/BelongsToParserLexer.rb +667 -0
  180. data/lib/tripper/model_parsers/belongs_to/BelongsToParserParser.rb +552 -0
  181. data/lib/tripper/model_parsers/belongs_to/playing_around.rb +9 -0
  182. data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParser.g +47 -0
  183. data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParser.tokens +14 -0
  184. data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParserLexer.rb +513 -0
  185. data/lib/tripper/model_parsers/database_fields_parser/DatabaseFieldsParserParser.rb +279 -0
  186. data/lib/tripper/model_parsers/database_fields_parser/playing_around.rb +14 -0
  187. data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParser.g +92 -0
  188. data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParser.tokens +25 -0
  189. data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParserLexer.rb +787 -0
  190. data/lib/tripper/model_parsers/has_and_belongs_to_many/HasAndBelongsToManyParserParser.rb +1024 -0
  191. data/lib/tripper/model_parsers/has_and_belongs_to_many/playing_around.rb +9 -0
  192. data/lib/tripper/model_parsers/has_many/HasManyParser.g +77 -0
  193. data/lib/tripper/model_parsers/has_many/HasManyParser.tokens +23 -0
  194. data/lib/tripper/model_parsers/has_many/HasManyParserLexer.rb +710 -0
  195. data/lib/tripper/model_parsers/has_many/HasManyParserParser.rb +788 -0
  196. data/lib/tripper/model_parsers/has_many/playing_around.rb +9 -0
  197. data/lib/tripper/model_parsers/has_one/HasOneParser.g +63 -0
  198. data/lib/tripper/model_parsers/has_one/HasOneParser.tokens +21 -0
  199. data/lib/tripper/model_parsers/has_one/HasOneParserLexer.rb +664 -0
  200. data/lib/tripper/model_parsers/has_one/HasOneParserParser.rb +552 -0
  201. data/lib/tripper/model_parsers/has_one/playing_around.rb +9 -0
  202. data/lib/tripper/model_parsers/validates/ValidatesParser.g +68 -0
  203. data/lib/tripper/model_parsers/validates/ValidatesParser.tokens +35 -0
  204. data/lib/tripper/model_parsers/validates/ValidatesParserLexer.rb +899 -0
  205. data/lib/tripper/model_parsers/validates/ValidatesParserParser.rb +869 -0
  206. data/lib/tripper/model_parsers/validates/playing_around.rb +9 -0
  207. data/lib/tripper/rails.rb +8 -0
  208. data/lib/tripper/version.rb +3 -0
  209. data/tripper.gemspec +33 -0
  210. metadata +408 -0
@@ -0,0 +1,423 @@
1
+ require 'active_record'
2
+ require 'logger'
3
+ require 'yaml'
4
+
5
+ module Tripper
6
+ module ORMDB
7
+ ORMDBCONFIG = YAML::load(File.open(File.dirname(__FILE__)+'/config/database.yml'))['development']
8
+ ActiveRecord::Base.logger = Logger.new(STDERR)
9
+
10
+ module ObjectType
11
+ def contains_identifying_constraint?
12
+ ! identifying_constraint_objects.empty?
13
+ end
14
+
15
+ # Will return a list of lists. Each of these list represent an external uniqueness constraint.
16
+ # e.g. [[NoLot1, NoLot2, NoLot3], [NoLot 8, NoLot9]]
17
+ def exernal_uniqueness_constraint_object_types
18
+ uniqueness_constraints_from_predicates.inject(OrmArray.new) do |res, constraint|
19
+ if constraint.object_roles.size > 1
20
+ pred_objects = constraint.object_roles.inject(OrmArray.new) do |res_con, objr|
21
+ res_con << objr.orm_object #unless objr.orm_object == self
22
+ res_con
23
+ end
24
+ #when self is in the array, we are part of someone else's external uniqueness.
25
+ res << pred_objects unless pred_objects.empty? || pred_objects.include?(self)
26
+ end
27
+ res
28
+ end
29
+ end
30
+
31
+ def object_types_identified_by_me
32
+ # uniqueness_constraints_from_predicates.inject(OrmArray.new) do |res, constraint|
33
+ # if constraint.object_roles.size == 1 && constraint.object_roles.first.orm_object != self
34
+ # res << constraint.object_roles.first.orm_object
35
+ # end
36
+ # res
37
+ # end
38
+ object_role_constraints.where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::UniquenessConstraint').inject(OrmArray.new) do |res, obj_role_const|
39
+ if obj_role_const.constraint.object_roles.count == 1
40
+ obj_role_const.object_role.predicate.object_roles.each do |objr|
41
+ unless objr.orm_object == self
42
+ res << objr.orm_object unless objr.orm_object.name < self.name
43
+ end
44
+ end
45
+ end
46
+ res
47
+ end
48
+ end
49
+
50
+ def has_many_object_types
51
+ object_role_ids= object_role_constraints.select('object_role_id').where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::UniquenessConstraint').map(&:object_role_id)
52
+ result = []
53
+ ors = object_role_ids.empty? ? object_roles : object_roles.where("id NOT IN (?)", object_role_ids) #sqlite does not support NOT EXISTS
54
+ ors.each do |objrole|
55
+ predicate = objrole.predicate
56
+ other_or = predicate.object_roles - [objrole]
57
+ result.concat other_or.map(&:orm_object)
58
+ end
59
+ result
60
+ end
61
+
62
+ def identifying_constraint_objects
63
+ object_role_constraints.where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::UniquenessConstraint').inject(OrmArray.new) do |res, obj_role_const|
64
+ if obj_role_const.constraint.object_roles.count == 1
65
+ obj_role_const.object_role.predicate.object_roles.each do |objr|
66
+ unless objr.orm_object == self
67
+ res << objr.orm_object if objr.orm_object.name < self.name
68
+ end
69
+ end
70
+ end
71
+ res
72
+ end
73
+ end
74
+
75
+ def mandatory_constraint_objects
76
+ object_role_constraints.where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::MandatoryConstraint').inject(OrmArray.new) do |res, obj_role_const|
77
+ if obj_role_const.constraint.object_roles.count == 1
78
+ obj_role_const.object_role.predicate.object_roles.each do |objr|
79
+ res << objr.orm_object unless objr.orm_object == self
80
+ end
81
+ end
82
+ res
83
+ end
84
+ end
85
+
86
+ def has_many
87
+ unique_obj_role_ids = object_role_constraints.where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::UniquenessConstraint').map(&:object_role_id)
88
+ many_object_roles = unique_obj_role_ids.empty? ? object_roles : object_roles.where("id not in (?)",unique_obj_role_ids)
89
+ result = many_object_roles.inject([]) do |res, obj_role|
90
+ #result = object_roles.inject([]) do |res, obj_role|
91
+ obj_role.predicate.object_roles.where("id != ?", obj_role.id).each do |op_role|
92
+ #check if the other role of the predicate has a uniqueness constraint
93
+ res << op_role unless op_role.uniqueness_constraints.empty?
94
+ end
95
+ res
96
+ end
97
+ result.map(&:orm_object)
98
+ end
99
+
100
+ def has_many_many
101
+ unique_obj_role_ids = object_role_constraints.where('object_role_constraints.constraint_type' => 'Tripper::ORMDB::UniquenessConstraint').map(&:object_role_id)
102
+ many_object_roles = unique_obj_role_ids.empty? ? object_roles : object_roles.where("id not in (?)",unique_obj_role_ids)
103
+ result = many_object_roles.inject([]) do |res, obj_role|
104
+ # res.concat(obj_role.predicate.object_roles.where("id != ?", obj_role.id))
105
+ obj_role.predicate.object_roles.where("id != ?", obj_role.id).each do |op_role|
106
+ #check if the other role of the predicate has a uniqueness constraint
107
+ res << op_role if op_role.uniqueness_constraints.empty?
108
+ end
109
+ res
110
+ end
111
+ result.map(&:orm_object)
112
+ end
113
+
114
+ # private
115
+
116
+ def uniqueness_constraints_from_predicates
117
+ #UniquenessConstraint.joins(:object_roles).where('object_roles.predicate_id' => predicates).group('object_roles.predicate_id').uniq
118
+ UniquenessConstraint.joins(:object_roles).where('object_roles.predicate_id' => predicates).uniq
119
+ end
120
+ end
121
+
122
+ class OrmArray < Array
123
+ def no_lots
124
+ self.select do |obj|
125
+ obj.is_a? Tripper::ORMDB::NoLot
126
+ end
127
+ end
128
+ def lots
129
+ self.select do |obj|
130
+ obj.is_a? Tripper::ORMDB::Lot
131
+ end
132
+ end
133
+ end
134
+
135
+ class OrmSchema < ActiveRecord::Base
136
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
137
+ attr_accessible :title, :creator, :version, :description, :origin, :last_visit
138
+ #has_many :orm_objects
139
+ has_many :no_lots, dependent: :destroy
140
+ has_many :lots, dependent: :destroy
141
+ has_many :subtypes, dependent: :destroy
142
+ has_many :no_lot_constraints, dependent: :destroy
143
+ has_many :references, dependent: :destroy
144
+ has_many :predicates, dependent: :destroy
145
+ has_many :object_roles, dependent: :destroy
146
+ has_many :object_role_constraints, dependent: :destroy
147
+ has_many :constraints, dependent: :destroy
148
+ has_many :mandatory_constraints, dependent: :destroy
149
+ has_many :uniqueness_constraints, dependent: :destroy
150
+ has_many :ring_constraints, dependent: :destroy
151
+ has_many :subset_constraints, dependent: :destroy
152
+ has_many :equality_constraints, dependent: :destroy
153
+ has_many :exclusion_constraints, dependent: :destroy
154
+ has_many :total_constraints, dependent: :destroy
155
+ has_many :exclusive_constraints, dependent: :destroy
156
+ has_many :frequency_constraints, dependent: :destroy
157
+ has_many :value_constraints, dependent: :destroy
158
+ has_many :value_constraint_values, dependent: :destroy
159
+ has_many :values, dependent: :destroy
160
+ has_many :value_ranges, dependent: :destroy
161
+
162
+ def object_types_by_name name
163
+ no_lots.where(:name => name) + lots.where(:name => name)
164
+ end
165
+
166
+ attr_protected
167
+ end
168
+
169
+ #class OrmObject < ActiveRecord::Base
170
+ # self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
171
+ # attr_accessible :id, :name, :orm_schema_id
172
+ # has_one :reference
173
+ # has_many :object_roles
174
+ # belongs_to :orm_schema
175
+ #end
176
+
177
+ class Lot < ActiveRecord::Base
178
+ include ObjectType
179
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
180
+ attr_accessible :id, :name, :numeric, :application_name
181
+ has_one :value_constraint, dependent: :destroy
182
+
183
+ attr_protected
184
+ end
185
+
186
+ class NoLot < ActiveRecord::Base
187
+ include ObjectType
188
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
189
+ attr_accessible :id, :name, :independant, :application_name
190
+ has_one :reference
191
+ has_many :object_roles, :as => :orm_object, dependent: :destroy
192
+ has_many :predicates, :through => :object_roles
193
+ belongs_to :orm_schema
194
+
195
+ has_many :object_role_constraints, :through => :object_roles
196
+
197
+ has_many :children, :through => :subtypes_by_parent_id
198
+ has_many :subtypes_by_parent_id, :class_name => "Subtype", :foreign_key => :parent_id
199
+
200
+ has_many :parents, :through => :subtypes_by_child_id
201
+ has_many :subtypes_by_child_id, :class_name => "Subtype", :foreign_key => :child_id
202
+
203
+ has_many :no_lot_constraints, dependent: :destroy
204
+ # these are helper methods to ensure that the role will be automatically set.
205
+ has_many :no_lot_constraints_role_supertype, :class_name => "Tripper::ORMDB::NoLotConstraint", :conditions => {:role => "supertype"}
206
+ has_many :no_lot_constraints_role_subtype, :class_name => "Tripper::ORMDB::NoLotConstraint", :conditions => {:role => "subtype"}
207
+
208
+ has_many :total_constraints_as_supertype, :through => :no_lot_constraints_role_supertype, :source => :constraint, :source_type => "Tripper::ORMDB::TotalConstraint"
209
+ has_many :total_constraints_as_subtype, :through => :no_lot_constraints_role_subtype, :source => :constraint, :source_type => "Tripper::ORMDB::TotalConstraint"
210
+ has_many :exclusive_constraints_as_supertype, :through => :no_lot_constraints_role_supertype, :source => :constraint, :source_type => "Tripper::ORMDB::ExclusiveConstraint"
211
+ has_many :exclusive_constraints_as_subtype, :through => :no_lot_constraints_role_subtype, :source => :constraint, :source_type => "Tripper::ORMDB::ExclusiveConstraint"
212
+
213
+ attr_protected
214
+ end
215
+
216
+ class Subtype < ActiveRecord::Base
217
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
218
+ belongs_to :parent, :class_name => "NoLot", :foreign_key => :parent_id
219
+ belongs_to :child, :class_name => "NoLot", :foreign_key => :child_id
220
+ belongs_to :orm_schema
221
+ attr_protected
222
+ end
223
+
224
+ class NoLotConstraint < ActiveRecord::Base
225
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
226
+ attr_accessible :role, :no_lot_id, :orm_schema_id
227
+ belongs_to :no_lot
228
+ belongs_to :constraint, :polymorphic => true, :dependent => :destroy
229
+ belongs_to :orm_schema
230
+ attr_protected
231
+ end
232
+
233
+ class Reference < ActiveRecord::Base
234
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
235
+ attr_accessible :id, :name, :numeric, :orm_schema_id
236
+ belongs_to :orm_object, :polymorphic => true
237
+ belongs_to :orm_schema
238
+ attr_protected
239
+ end
240
+
241
+ class Predicate < ActiveRecord::Base
242
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
243
+ attr_accessible :derived, :derived_stored, :predicate_object, :predicate_name, :orm_schema_id, :identifier
244
+ has_many :object_roles, dependent: :destroy
245
+ has_many :object_role_constraints, :through => :object_roles
246
+ belongs_to :orm_schema
247
+ has_many :orm_objects, :through => :object_roles
248
+ has_many :nolots_obj_roles, as: :orm_object, class_name: "Tripper::ORMDB::ObjectRole", conditions: {orm_object_type: 'Tripper::ORMDB::NoLot'}
249
+ has_many :nolots, through: :object_roles, source: :orm_object, source_type: "Tripper::ORMDB::NoLot", class_name: "Tripper::ORMDB::NoLot"
250
+ has_many :lots, through: :object_roles, source: :orm_object, source_type: "Tripper::ORMDB::Lot", class_name: "Tripper::ORMDB::Lot"
251
+ #validates_uniqueness_of :identifier, :scope => :orm_schema_id
252
+ attr_protected
253
+
254
+ def self.verbalized_lexons
255
+ res = []
256
+ all.each do |pred|
257
+ verbelization = ""
258
+ pred.object_roles.each do |obj_role|
259
+ verbelization += obj_role.orm_object.name
260
+ #verbelization += obj_role.role
261
+ end
262
+ res << verbelization
263
+ end
264
+ return res
265
+ end
266
+ end
267
+
268
+ class ObjectRole < ActiveRecord::Base
269
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
270
+ attr_accessible :role, :identifier, :orm_object_id, :orm_object_type, :orm_schema_id
271
+ belongs_to :predicate
272
+ belongs_to :orm_object, :polymorphic => true
273
+ belongs_to :orm_schema
274
+ has_many :object_role_constraints, dependent: :destroy
275
+ # these are helper methods to ensure that the role will be automatically set.
276
+ has_many :object_role_constraints_role_parent, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :conditions => {:role => "parent"}
277
+ has_many :object_role_constraints_role_child, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :conditions => {:role => "child"}
278
+ has_many :object_role_constraints_role_first, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :conditions => {:role => "first"}
279
+ has_many :object_role_constraints_role_second, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :conditions => {:role => "second"}
280
+
281
+ has_many :mandatory_constraints, :through => :object_role_constraints, :source => :constraint, :source_type => "Tripper::ORMDB::MandatoryConstraint"
282
+ has_many :uniqueness_constraints, :through => :object_role_constraints, :source => :constraint, :source_type => "Tripper::ORMDB::UniquenessConstraint"
283
+ has_many :subset_constraints_as_parent, :through => :object_role_constraints_role_parent, :source => :constraint, :source_type => "Tripper::ORMDB::SubsetConstraint"
284
+ has_many :subset_constraints_as_child, :through => :object_role_constraints_role_child, :source => :constraint, :source_type => "Tripper::ORMDB::SubsetConstraint"
285
+ has_many :equality_constraints_as_first, :through => :object_role_constraints_role_first, :source => :constraint, :source_type => "Tripper::ORMDB::EqualityConstraint"
286
+ has_many :equality_constraints_as_second, :through => :object_role_constraints_role_second, :source => :constraint, :source_type => "Tripper::ORMDB::EqualityConstraint"
287
+ has_many :exclusion_constraints_as_first, :through => :object_role_constraints_role_first, :source => :constraint, :source_type => "Tripper::ORMDB::ExclusionConstraint"
288
+ has_many :exclusion_constraints_as_second, :through => :object_role_constraints_role_second, :source => :constraint, :source_type => "Tripper::ORMDB::ExclusionConstraint"
289
+ has_one :frequency_constraint
290
+
291
+ has_one :ring_constraint, :through => :object_role_constraint_single, :source => :constraint, :source_type => "Tripper::ORMDB::RingConstraint"
292
+ has_one :object_role_constraint_single, :class_name => "Tripper::ORMDB::ObjectRoleConstraint"
293
+ attr_protected
294
+ end
295
+
296
+ class ObjectRoleConstraint < ActiveRecord::Base
297
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
298
+ attr_accessible :constraint_id, :constraint_type, :orm_schema_id, :role #to denotate things such as: parent, child, first etc..
299
+ belongs_to :object_role
300
+ belongs_to :constraint, :polymorphic => true
301
+ belongs_to :orm_schema
302
+ attr_protected
303
+ end
304
+
305
+ class Constraint < ActiveRecord::Base
306
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
307
+ belongs_to :orm_schema
308
+ attr_protected
309
+ end
310
+
311
+ class MandatoryConstraint < ActiveRecord::Base
312
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
313
+ attr_accessible :type, :orm_schema_id, :identifier
314
+ has_many :object_roles, :through => :object_role_constraints
315
+ has_many :object_role_constraints, :as => :constraint
316
+ attr_protected
317
+ end
318
+
319
+ class UniquenessConstraint < ActiveRecord::Base
320
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
321
+ has_many :object_roles, :through => :object_role_constraints
322
+ has_many :object_role_constraints, :as => :constraint
323
+ attr_protected
324
+ end
325
+
326
+ class RingConstraint < ActiveRecord::Base
327
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
328
+ attr_accessible :kind, :orm_schema_id
329
+ belongs_to :orm_schema
330
+ validates :kind, :inclusion => { :in => %w(antisymmetric asymmetric acyclic irreflexive intransitive symmetric acyclic+intransitive asymmetric+intransitive intransitive+symmetric irreflexive+symmetric),
331
+ :message => "%{value} is not a valid ring contraint type"}
332
+ has_many :object_roles, :through => :object_role_constraints
333
+ has_many :object_role_constraints, :as => :constraint, :conditions => {:constraint_type => "Tripper::ORMDB::RingConstraint"}
334
+ attr_protected
335
+ end
336
+
337
+ class SubsetConstraint < Constraint
338
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
339
+ has_many :parents, :through => :object_role_constraints_role_parent, :source => :object_role
340
+ has_many :children, :through => :object_role_constraints_role_child, :source => :object_role
341
+ has_many :object_role_constraints_role_parent, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint , :conditions => {:role => "parent", :constraint_type => "Tripper::ORMDB::SubsetConstraint"}
342
+ has_many :object_role_constraints_role_child, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint , :conditions => {:role => "child", :constraint_type => "Tripper::ORMDB::SubsetConstraint"}
343
+ attr_protected
344
+ end
345
+
346
+ class EqualityConstraint < Constraint
347
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
348
+ has_many :first, :through => :object_role_constraints_role_first, :source => :object_role
349
+ has_many :second, :through => :object_role_constraints_role_second, :source => :object_role
350
+ has_many :object_role_constraints_role_first, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint, :conditions => {:role => "first", :constraint_type => "Tripper::ORMDB::EqualityConstraint"}
351
+ has_many :object_role_constraints_role_second, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint, :conditions => {:role => "second", :constraint_type => "Tripper::ORMDB::EqualityConstraint"}
352
+ attr_protected
353
+ end
354
+
355
+ class ExclusionConstraint < Constraint
356
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
357
+ has_many :first, :through => :object_role_constraints_role_first, :source => :object_role
358
+ has_many :second, :through => :object_role_constraints_role_second, :source => :object_role
359
+ has_many :object_role_constraints_role_first, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint, :conditions => {:role => "first", :constraint_type => "Tripper::ORMDB::ExclusionConstraint"}
360
+ has_many :object_role_constraints_role_second, :class_name => "Tripper::ORMDB::ObjectRoleConstraint", :as => :constraint, :conditions => {:role => "second", :constraint_type => "Tripper::ORMDB::ExclusionConstraint"}
361
+ attr_protected
362
+ end
363
+
364
+ class TotalConstraint < Constraint
365
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
366
+ has_one :supertype, :through => :no_lot_constraints_role_supertype, :source => :no_lot
367
+ has_many :subtypes, :through => :no_lot_constraints_role_subtype, :source => :no_lot
368
+ has_one :no_lot_constraints_role_supertype, :class_name => "Tripper::ORMDB::NoLotConstraint", :as => :constraint, :conditions => {:role => "supertype", :constraint_type => "Tripper::ORMDB::TotalConstraint"}
369
+ has_many :no_lot_constraints_role_subtype, :class_name => "Tripper::ORMDB::NoLotConstraint", :as => :constraint, :conditions => {:role => "subtype", :constraint_type => "Tripper::ORMDB::TotalConstraint"}
370
+ attr_protected
371
+ end
372
+
373
+ class ExclusiveConstraint < Constraint
374
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
375
+ has_one :supertype, :through => :no_lot_constraints_role_supertype, :source => :no_lot
376
+ has_many :subtypes, :through => :no_lot_constraints_role_subtype, :source => :no_lot
377
+ has_one :no_lot_constraints_role_supertype, :class_name => "Tripper::ORMDB::NoLotConstraint", :as => :constraint, :conditions => {:role => "supertype", :constraint_type => "Tripper::ORMDB::ExclusiveConstraint"}
378
+ has_many :no_lot_constraints_role_subtype, :class_name => "Tripper::ORMDB::NoLotConstraint", :as => :constraint, :conditions => {:role => "subtype", :constraint_type => "Tripper::ORMDB::ExclusiveConstraint"}
379
+ attr_protected
380
+ end
381
+
382
+ class FrequencyConstraint < ActiveRecord::Base
383
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
384
+ belongs_to :orm_schema
385
+ attr_accessible :minimum, :maximum
386
+ belongs_to :object_role
387
+ attr_protected
388
+ end
389
+
390
+ class ValueConstraint < ActiveRecord::Base
391
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
392
+ belongs_to :orm_schema
393
+ belongs_to :lot
394
+ has_many :values, :through => :value_constraint_values,:source => :valueish, :source_type => "Value"
395
+ has_many :value_ranges, :through => :value_constraint_values, :source => :valueish, :source_type => "ValueRange"
396
+ has_many :value_constraint_values
397
+ attr_protected
398
+ end
399
+
400
+ class ValueConstraintValue < ActiveRecord::Base
401
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
402
+ belongs_to :orm_schema
403
+ belongs_to :value_constraint
404
+ belongs_to :valueish, :polymorphic => true, :dependent => :destroy
405
+ attr_protected
406
+ end
407
+
408
+ class Value < ActiveRecord::Base
409
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
410
+ belongs_to :orm_schema
411
+ attr_accessible :data_type, :value
412
+ attr_protected
413
+ end
414
+
415
+ class ValueRange < ActiveRecord::Base
416
+ self.establish_connection(Tripper::ORMDB::ORMDBCONFIG)
417
+ belongs_to :orm_schema
418
+ belongs_to :start_value, :class_name => "Value"
419
+ belongs_to :end_value, :class_name => "Value"
420
+ attr_protected
421
+ end
422
+ end
423
+ end
@@ -0,0 +1,4 @@
1
+ @q = Tripper::ORMDB::NoLot.find 1
2
+ @w = Tripper::ORMDB::NoLot.find 2
3
+ @e = Tripper::ORMDB::NoLot.find 3
4
+ @r = Tripper::ORMDB::NoLot.find 4
@@ -0,0 +1,88 @@
1
+ require 'yaml'
2
+ require 'logger'
3
+ require 'active_record'
4
+
5
+ namespace :db do
6
+ def create_database config
7
+ options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
8
+
9
+ create_db = lambda do |config|
10
+ #ActiveRecord::Base.establish_connection config.merge('database' => nil)
11
+ ActiveRecord::Base.connection.create_database config['database']
12
+ ActiveRecord::Base.establish_connection config
13
+ end
14
+ create_db.call config
15
+
16
+ end
17
+
18
+ task :environment do
19
+ DATABASE_ENV = ENV['DATABASE_ENV'] || 'development'
20
+ MIGRATIONS_DIR = ENV['MIGRATIONS_DIR'] || 'db/migrations'
21
+ end
22
+
23
+ task :configuration => :environment do
24
+ @config = YAML.load_file('config/database.yml')[DATABASE_ENV]
25
+ puts @config
26
+ end
27
+
28
+ task :configure_connection => :configuration do
29
+ ActiveRecord::Base.establish_connection @config
30
+ ActiveRecord::Base.logger = Logger.new STDOUT if @config['logger']
31
+ end
32
+
33
+ desc 'Create the database from config/database.yml for the current DATABASE_ENV'
34
+ task :create => :configure_connection do
35
+ create_database @config
36
+ end
37
+
38
+ desc 'Drops the database for the current DATABASE_ENV'
39
+ task :drop => :configure_connection do
40
+ ActiveRecord::Base.connection.drop_database @config['database']
41
+ end
42
+
43
+ desc 'Migrate the database (options: VERSION=x, VERBOSE=false).'
44
+ task :migrate => :configure_connection do
45
+ ActiveRecord::Migration.verbose = true
46
+ ActiveRecord::Migrator.migrate MIGRATIONS_DIR, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
47
+ end
48
+
49
+ desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
50
+ task :rollback => :configure_connection do
51
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
52
+ ActiveRecord::Migrator.rollback MIGRATIONS_DIR, step
53
+ end
54
+
55
+ desc "drops all the tables"
56
+ task :drop => :configure_connection do
57
+ ENV['VERSION'] = "0"
58
+ Rake::Task['db:migrate'].invoke
59
+ end
60
+
61
+ desc "drops all the tables and creates them again"
62
+ task :reset => :configure_connection do
63
+ ENV['STEP'] = "#{ActiveRecord::Migrator.current_version}"
64
+ Rake::Task['db:rollback'].invoke
65
+ Rake::Task['db:migrate'].invoke
66
+ end
67
+
68
+ desc "Retrieves the current schema version number"
69
+ task :version => :configure_connection do
70
+ puts "Current version: #{ActiveRecord::Migrator.current_version}"
71
+ end
72
+
73
+ namespace :schema do
74
+ desc "Create a db/ar_schema.rb file that can be portably used against any DB supported by AR"
75
+ task :dump => :configure_connection do
76
+ require 'active_record/schema_dumper'
77
+ File.open(ENV['SCHEMA'] || "db/schema.rb", "w") do |file|
78
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
79
+ end
80
+ end
81
+
82
+ desc "Load a ar_schema.rb file into the database"
83
+ task :load => :configure_connection do
84
+ file = ENV['SCHEMA'] || "db/schema.rb"
85
+ load(file)
86
+ end
87
+ end
88
+ end