rdl 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (252) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -0
  3. data/CHANGES.md +35 -0
  4. data/README.md +153 -116
  5. data/bin/rdl_query +1 -1
  6. data/extras/type_tests/typetests.rb +905 -0
  7. data/lib/rdl.rb +0 -1
  8. data/lib/rdl/boot.rb +108 -77
  9. data/lib/rdl/boot_rails.rb +2 -8
  10. data/lib/rdl/config.rb +44 -17
  11. data/lib/rdl/contracts/flat.rb +1 -1
  12. data/lib/rdl/info.rb +3 -3
  13. data/lib/rdl/query.rb +11 -11
  14. data/lib/rdl/typecheck.rb +399 -136
  15. data/lib/rdl/types/finite_hash.rb +3 -2
  16. data/lib/rdl/types/generic.rb +7 -6
  17. data/lib/rdl/types/intersection.rb +3 -2
  18. data/lib/rdl/types/lexer.rex +2 -3
  19. data/lib/rdl/types/lexer.rex.rb +1 -4
  20. data/lib/rdl/types/method.rb +7 -6
  21. data/lib/rdl/types/nominal.rb +10 -1
  22. data/lib/rdl/types/parser.racc +7 -8
  23. data/lib/rdl/types/parser.tab.rb +108 -109
  24. data/lib/rdl/types/structural.rb +1 -0
  25. data/lib/rdl/types/tuple.rb +2 -2
  26. data/lib/rdl/types/type.rb +8 -8
  27. data/lib/rdl/types/type_inferencer.rb +1 -1
  28. data/lib/rdl/types/union.rb +2 -1
  29. data/lib/rdl/util.rb +28 -3
  30. data/lib/rdl/wrap.rb +216 -165
  31. data/lib/rdl_disable.rb +22 -15
  32. data/lib/types/core.rb +2 -4
  33. data/lib/types/core/_aliases.rb +14 -0
  34. data/lib/types/core/abbrev.rb +3 -0
  35. data/lib/types/core/array.rb +139 -0
  36. data/lib/types/core/base64.rb +8 -0
  37. data/lib/types/core/basic_object.rb +12 -0
  38. data/lib/types/core/benchmark.rb +9 -0
  39. data/lib/types/core/bigdecimal.rb +223 -0
  40. data/lib/types/core/bigmath.rb +10 -0
  41. data/lib/types/core/bignum.rb +214 -0
  42. data/lib/types/core/class.rb +15 -0
  43. data/lib/types/core/complex.rb +123 -0
  44. data/lib/types/core/coverage.rb +4 -0
  45. data/lib/types/core/csv.rb +3 -0
  46. data/lib/types/core/date.rb +4 -0
  47. data/lib/types/core/dir.rb +37 -0
  48. data/lib/types/core/encoding.rb +21 -0
  49. data/lib/types/core/enumerable.rb +96 -0
  50. data/lib/types/core/enumerator.rb +24 -0
  51. data/lib/types/core/exception.rb +15 -0
  52. data/lib/types/core/file.rb +125 -0
  53. data/lib/types/core/fileutils.rb +4 -0
  54. data/lib/types/core/fixnum.rb +213 -0
  55. data/lib/types/core/float.rb +199 -0
  56. data/lib/types/core/gem.rb +19 -0
  57. data/lib/types/core/hash.rb +72 -0
  58. data/lib/types/core/integer.rb +194 -0
  59. data/lib/types/core/io.rb +101 -0
  60. data/lib/types/core/kernel.rb +89 -0
  61. data/lib/types/core/marshal.rb +3 -0
  62. data/lib/types/core/matchdata.rb +24 -0
  63. data/lib/types/core/math.rb +50 -0
  64. data/lib/types/core/module.rb +81 -0
  65. data/lib/types/core/nil.rb +11 -0
  66. data/lib/types/core/numeric.rb +56 -0
  67. data/lib/types/core/object.rb +73 -0
  68. data/lib/types/core/pathname.rb +104 -0
  69. data/lib/types/core/proc.rb +12 -0
  70. data/lib/types/core/process.rb +110 -0
  71. data/lib/types/core/random.rb +13 -0
  72. data/lib/types/core/range.rb +37 -0
  73. data/lib/types/core/rational.rb +207 -0
  74. data/lib/types/core/regexp.rb +28 -0
  75. data/lib/types/core/set.rb +56 -0
  76. data/lib/types/core/string.rb +140 -0
  77. data/lib/types/core/strscan.rb +6 -0
  78. data/lib/types/core/symbol.rb +27 -0
  79. data/lib/types/core/time.rb +66 -0
  80. data/lib/types/core/uri.rb +18 -0
  81. data/lib/types/core/yaml.rb +3 -0
  82. data/lib/types/devise.rb +1 -0
  83. data/lib/types/devise/controller_helpers.rb +3 -0
  84. data/lib/types/devise/parameter_sanitizer.rb +2 -0
  85. data/lib/types/pundit.rb +2 -0
  86. data/lib/types/rails/_helpers.rb +50 -0
  87. data/lib/types/rails/abstract_controller/translation.rb +2 -0
  88. data/lib/types/rails/action_controller/base.rb +3 -0
  89. data/lib/types/rails/action_controller/instrumentation.rb +6 -0
  90. data/lib/types/rails/action_controller/metal.rb +3 -0
  91. data/lib/types/rails/action_controller/mime_responds.rb +13 -0
  92. data/lib/types/rails/action_controller/parameters.rb +3 -0
  93. data/lib/types/{rails-5.x → rails}/action_controller/strong_parameters.rb +4 -8
  94. data/lib/types/rails/action_dispatch/flashhash.rb +8 -0
  95. data/lib/types/rails/action_dispatch/routing.rb +10 -0
  96. data/lib/types/rails/action_mailer/base.rb +2 -0
  97. data/lib/types/rails/action_mailer/message_delivery.rb +2 -0
  98. data/lib/types/rails/action_view/helpers_sanitizehelper.rb +2 -0
  99. data/lib/types/rails/action_view/helpers_urlhelper.rb +5 -0
  100. data/lib/types/rails/active_model/errors.rb +14 -0
  101. data/lib/types/rails/active_model/validations.rb +2 -0
  102. data/lib/types/rails/active_record/associations.rb +208 -0
  103. data/lib/types/rails/active_record/base.rb +2 -0
  104. data/lib/types/rails/active_record/core.rb +2 -0
  105. data/lib/types/rails/active_record/finder_methods.rb +2 -0
  106. data/lib/types/rails/active_record/model_schema.rb +37 -0
  107. data/lib/types/rails/active_record/relation.rb +11 -0
  108. data/lib/types/rails/active_record/schema_types.rb +51 -0
  109. data/lib/types/rails/active_record/validations.rb +2 -0
  110. data/lib/types/rails/active_support/base.rb +2 -0
  111. data/lib/types/rails/active_support/logger.rb +3 -0
  112. data/lib/types/rails/active_support/tagged_logging.rb +2 -0
  113. data/lib/types/rails/active_support/time_with_zone.rb +13 -0
  114. data/lib/types/rails/active_support/time_zone.rb +2 -0
  115. data/lib/types/rails/fixnum.rb +2 -0
  116. data/lib/types/rails/integer.rb +2 -0
  117. data/lib/types/rails/rack/request.rb +2 -0
  118. data/lib/types/rails/string.rb +3 -0
  119. data/lib/types/rails/time.rb +1 -0
  120. data/rdl.gemspec +2 -2
  121. data/test/disabled_test_rdoc.rb +8 -8
  122. data/test/test_alias.rb +1 -0
  123. data/test/test_dsl.rb +4 -4
  124. data/test/test_generic.rb +45 -38
  125. data/test/test_intersection.rb +10 -10
  126. data/test/test_le.rb +103 -102
  127. data/test/test_member.rb +33 -33
  128. data/test/test_parser.rb +101 -96
  129. data/test/test_query.rb +84 -84
  130. data/test/test_rdl.rb +87 -52
  131. data/test/test_rdl_type.rb +26 -9
  132. data/test/test_type_contract.rb +32 -31
  133. data/test/test_typecheck.rb +802 -436
  134. data/test/test_types.rb +39 -39
  135. data/test/test_wrap.rb +3 -2
  136. metadata +91 -120
  137. data/extras/type_tests/%.rb +0 -171
  138. data/extras/type_tests/&.rb +0 -159
  139. data/extras/type_tests/**.rb +0 -222
  140. data/extras/type_tests/*.rb +0 -177
  141. data/extras/type_tests/+.rb +0 -170
  142. data/extras/type_tests/-.rb +0 -171
  143. data/extras/type_tests/1scomp.rb +0 -157
  144. data/extras/type_tests/<.rb +0 -170
  145. data/extras/type_tests/<<.rb +0 -159
  146. data/extras/type_tests/>>.rb +0 -159
  147. data/extras/type_tests/[].rb +0 -163
  148. data/extras/type_tests/^.rb +0 -159
  149. data/extras/type_tests/abs.rb +0 -155
  150. data/extras/type_tests/abs2.rb +0 -164
  151. data/extras/type_tests/angle.rb +0 -157
  152. data/extras/type_tests/arg.rb +0 -157
  153. data/extras/type_tests/bit_length.rb +0 -157
  154. data/extras/type_tests/ceil.rb +0 -157
  155. data/extras/type_tests/ceilRational.rb +0 -160
  156. data/extras/type_tests/conj.rb +0 -158
  157. data/extras/type_tests/defwhere.rb +0 -86
  158. data/extras/type_tests/denominator.rb +0 -157
  159. data/extras/type_tests/div.rb +0 -172
  160. data/extras/type_tests/divslash.rb +0 -179
  161. data/extras/type_tests/even?.rb +0 -157
  162. data/extras/type_tests/fdiv.rb +0 -244
  163. data/extras/type_tests/finite?.rb +0 -157
  164. data/extras/type_tests/floor.rb +0 -157
  165. data/extras/type_tests/floorRational.rb +0 -161
  166. data/extras/type_tests/hash.rb +0 -157
  167. data/extras/type_tests/imag.rb +0 -158
  168. data/extras/type_tests/infinite?.rb +0 -157
  169. data/extras/type_tests/modulo.rb +0 -171
  170. data/extras/type_tests/nan?.rb +0 -157
  171. data/extras/type_tests/neg.rb +0 -155
  172. data/extras/type_tests/next.rb +0 -157
  173. data/extras/type_tests/next_float.rb +0 -157
  174. data/extras/type_tests/numerator.rb +0 -157
  175. data/extras/type_tests/phase.rb +0 -157
  176. data/extras/type_tests/prev_float.rb +0 -157
  177. data/extras/type_tests/quo.rb +0 -179
  178. data/extras/type_tests/rationalize.rb +0 -157
  179. data/extras/type_tests/rationalizeArg.rb +0 -198
  180. data/extras/type_tests/real.rb +0 -157
  181. data/extras/type_tests/real?.rb +0 -157
  182. data/extras/type_tests/round.rb +0 -157
  183. data/extras/type_tests/roundArg.rb +0 -169
  184. data/extras/type_tests/size.rb +0 -157
  185. data/extras/type_tests/to_c.rb +0 -157
  186. data/extras/type_tests/to_f.rb +0 -155
  187. data/extras/type_tests/to_i.rb +0 -157
  188. data/extras/type_tests/to_r.rb +0 -157
  189. data/extras/type_tests/to_s.rb +0 -157
  190. data/extras/type_tests/truncate.rb +0 -157
  191. data/extras/type_tests/truncateArg.rb +0 -166
  192. data/extras/type_tests/type tests +0 -1
  193. data/extras/type_tests/zero?.rb +0 -155
  194. data/extras/type_tests/|.rb +0 -159
  195. data/lib/types/core-ruby-2.x/_aliases.rb +0 -15
  196. data/lib/types/core-ruby-2.x/abbrev.rb +0 -5
  197. data/lib/types/core-ruby-2.x/array.rb +0 -137
  198. data/lib/types/core-ruby-2.x/base64.rb +0 -10
  199. data/lib/types/core-ruby-2.x/basic_object.rb +0 -14
  200. data/lib/types/core-ruby-2.x/benchmark.rb +0 -11
  201. data/lib/types/core-ruby-2.x/bigdecimal.rb +0 -224
  202. data/lib/types/core-ruby-2.x/bigmath.rb +0 -12
  203. data/lib/types/core-ruby-2.x/bignum.rb +0 -214
  204. data/lib/types/core-ruby-2.x/class.rb +0 -17
  205. data/lib/types/core-ruby-2.x/complex.rb +0 -124
  206. data/lib/types/core-ruby-2.x/coverage.rb +0 -6
  207. data/lib/types/core-ruby-2.x/csv.rb +0 -5
  208. data/lib/types/core-ruby-2.x/date.rb +0 -6
  209. data/lib/types/core-ruby-2.x/dir.rb +0 -38
  210. data/lib/types/core-ruby-2.x/encoding.rb +0 -23
  211. data/lib/types/core-ruby-2.x/enumerable.rb +0 -98
  212. data/lib/types/core-ruby-2.x/enumerator.rb +0 -26
  213. data/lib/types/core-ruby-2.x/exception.rb +0 -17
  214. data/lib/types/core-ruby-2.x/file.rb +0 -126
  215. data/lib/types/core-ruby-2.x/fileutils.rb +0 -6
  216. data/lib/types/core-ruby-2.x/fixnum.rb +0 -213
  217. data/lib/types/core-ruby-2.x/float.rb +0 -199
  218. data/lib/types/core-ruby-2.x/gem.rb +0 -247
  219. data/lib/types/core-ruby-2.x/hash.rb +0 -72
  220. data/lib/types/core-ruby-2.x/integer.rb +0 -197
  221. data/lib/types/core-ruby-2.x/io.rb +0 -103
  222. data/lib/types/core-ruby-2.x/kernel.rb +0 -90
  223. data/lib/types/core-ruby-2.x/marshal.rb +0 -5
  224. data/lib/types/core-ruby-2.x/matchdata.rb +0 -26
  225. data/lib/types/core-ruby-2.x/math.rb +0 -53
  226. data/lib/types/core-ruby-2.x/module.rb +0 -83
  227. data/lib/types/core-ruby-2.x/nil.rb +0 -12
  228. data/lib/types/core-ruby-2.x/numeric.rb +0 -56
  229. data/lib/types/core-ruby-2.x/object.rb +0 -75
  230. data/lib/types/core-ruby-2.x/pathname.rb +0 -106
  231. data/lib/types/core-ruby-2.x/proc.rb +0 -16
  232. data/lib/types/core-ruby-2.x/process.rb +0 -127
  233. data/lib/types/core-ruby-2.x/random.rb +0 -17
  234. data/lib/types/core-ruby-2.x/range.rb +0 -39
  235. data/lib/types/core-ruby-2.x/rational.rb +0 -209
  236. data/lib/types/core-ruby-2.x/regexp.rb +0 -30
  237. data/lib/types/core-ruby-2.x/set.rb +0 -58
  238. data/lib/types/core-ruby-2.x/string.rb +0 -143
  239. data/lib/types/core-ruby-2.x/strscan.rb +0 -7
  240. data/lib/types/core-ruby-2.x/symbol.rb +0 -29
  241. data/lib/types/core-ruby-2.x/time.rb +0 -68
  242. data/lib/types/core-ruby-2.x/uri.rb +0 -20
  243. data/lib/types/core-ruby-2.x/yaml.rb +0 -5
  244. data/lib/types/rails-5.x/_helpers.rb +0 -52
  245. data/lib/types/rails-5.x/action_controller/mime_responds.rb +0 -11
  246. data/lib/types/rails-5.x/action_dispatch/routing.rb +0 -10
  247. data/lib/types/rails-5.x/active_model/errors.rb +0 -15
  248. data/lib/types/rails-5.x/active_model/validations.rb +0 -5
  249. data/lib/types/rails-5.x/active_record/associations.rb +0 -190
  250. data/lib/types/rails-5.x/active_record/core.rb +0 -3
  251. data/lib/types/rails-5.x/active_record/model_schema.rb +0 -39
  252. data/lib/types/rails-5.x/fixnum.rb +0 -3
@@ -0,0 +1,6 @@
1
+ RDL.nowrap :StringScanner
2
+
3
+ RDL.type :StringScanner, 'self.new', '(String, ?%bool) -> StringScanner'
4
+ RDL.type :StringScanner, :eos?, '() -> %bool'
5
+ RDL.type :StringScanner, :scan, '(Regexp) -> String'
6
+ RDL.type :StringScanner, :getch, '() -> String'
@@ -0,0 +1,27 @@
1
+ RDL.nowrap :Symbol
2
+
3
+ RDL.type :Symbol, 'self.all_symbols', '() -> Array<Symbol>'
4
+ RDL.type :Symbol, :<=>, '(Symbol other) -> Integer or nil'
5
+ RDL.type :Symbol, :==, '(%any obj) -> %bool'
6
+ RDL.type :Symbol, :=~, '(%any obj) -> Integer or nil'
7
+ RDL.type :Symbol, :[], '(Integer idx) -> String'
8
+ RDL.type :Symbol, :[], '(Integer b, Integer n) -> String'
9
+ RDL.type :Symbol, :[], '(Range<Integer>) -> String'
10
+ RDL.type :Symbol, :capitalize, '() -> Symbol'
11
+ RDL.type :Symbol, :casecmp, '(Symbol other) -> Integer or nil'
12
+ RDL.type :Symbol, :downcase, '() -> Symbol'
13
+ RDL.type :Symbol, :empty?, '() -> %bool'
14
+ RDL.type :Symbol, :encoding, '() -> Encoding'
15
+ RDL.type :Symbol, :id2name, '() -> String'
16
+ RDL.type :Symbol, :inspect, '() -> String'
17
+ RDL.type :Symbol, :intern, '() -> self'
18
+ RDL.type :Symbol, :length, '() -> Integer'
19
+ RDL.type :Symbol, :match, '(%any obj) -> Integer or nil'
20
+ RDL.type :Symbol, :succ, '() -> Symbol'
21
+ RDL.rdl_alias :Symbol, :size, :length
22
+ RDL.rdl_alias :Symbol, :slice, :[]
23
+ RDL.type :Symbol, :swapcase, '() -> Symbol'
24
+ RDL.type :Symbol, :to_proc, '() -> Proc' # TODO proc
25
+ RDL.rdl_alias :Symbol, :to_s, :id2name
26
+ RDL.rdl_alias :Symbol, :to_sym, :intern
27
+ RDL.type :Symbol, :upcase, '() -> Symbol'
@@ -0,0 +1,66 @@
1
+ RDL.nowrap :Time
2
+
3
+ RDL.type :Time, 'self.at', '(Time) -> Time'
4
+ RDL.type :Time, 'self.at', '(Numeric seconds_with_frac) -> Time'
5
+ RDL.type :Time, 'self.at', '(Numeric seconds, Numeric microseconds_with_frac) -> Time'
6
+ RDL.type :Time, 'self.gm', '(Integer year, ?(Integer or String) month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
7
+ RDL.type :Time, 'self.local', '(Integer year, ?(Integer or String) month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
8
+ RDL.rdl_alias :Time, 'self.mktime', 'self.local'
9
+ RDL.type :Time, :initialize, '(?Integer year, ?(Integer or String) month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> self'
10
+ RDL.type :Time, 'self.now', '() -> Time'
11
+ RDL.type :Time, 'self.utc', '(Integer year, ?(Integer or String) month, ?Integer day, ?Integer hour, ?Integer min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
12
+
13
+ RDL.type :Time, :+, '(Numeric) -> Time'
14
+ RDL.type :Time, :-, '(Time) -> Float'
15
+ RDL.type :Time, :-, '(Numeric) -> Time'
16
+ RDL.type :Time, :<=>, '(Time other) -> -1 or 0 or 1 or nil'
17
+ RDL.type :Time, :asctime, '() -> String'
18
+ RDL.type :Time, :ctime, '() -> String'
19
+ RDL.type :Time, :day, '() -> Integer'
20
+ RDL.type :Time, :dst?, '() -> %bool'
21
+ RDL.type :Time, :eql?, '(%any) -> %bool'
22
+ RDL.type :Time, :friday?, '() -> %bool'
23
+ RDL.type :Time, :getgm, '() -> Time'
24
+ RDL.type :Time, :getlocal, '(?Integer utc_offset) -> Time'
25
+ RDL.type :Time, :getutc, '() -> Time'
26
+ RDL.type :Time, :gmt?, '() -> %bool'
27
+ RDL.type :Time, :gmt_offset, '() -> Integer'
28
+ RDL.type :Time, :gmtime, '() -> self'
29
+ RDL.rdl_alias :Time, :gmtoff, :gmt_offset
30
+ RDL.type :Time, :hash, '() -> Integer'
31
+ RDL.type :Time, :hour, '() -> Integer'
32
+ RDL.type :Time, :inspect, '() -> String'
33
+ RDL.type :Time, :isdst, '() -> %bool'
34
+ RDL.type :Time, :localtime, '(?String utc_offset) -> self'
35
+ RDL.type :Time, :mday, '() -> Integer'
36
+ RDL.type :Time, :min, '() -> Integer'
37
+ RDL.type :Time, :mon, '() -> Integer'
38
+ RDL.type :Time, :monday?, '() -> %bool'
39
+ RDL.rdl_alias :Time, :month, :mon
40
+ RDL.type :Time, :nsec, '() -> Integer'
41
+ RDL.type :Time, :round, '(Integer) -> Time'
42
+ RDL.type :Time, :saturday, '() -> %bool'
43
+ RDL.type :Time, :sec, '() -> Integer'
44
+ RDL.type :Time, :strftime, '(String) -> String'
45
+ RDL.type :Time, :subsec, '() -> Numeric'
46
+ RDL.type :Time, :succ, '() -> Time'
47
+ RDL.type :Time, :sunday?, '() -> %bool'
48
+ RDL.type :Time, :thursday?, '() -> %bool'
49
+ RDL.type :Time, :to_a, '() -> [Integer, Integer, Integer, Integer, Integer, Integer, Integer, Integer, %bool, String]'
50
+ RDL.type :Time, :to_f, '() -> Float'
51
+ RDL.type :Time, :to_i, '() -> Numeric'
52
+ RDL.type :Time, :to_r, '() -> Rational'
53
+ RDL.type :Time, :to_s, '() -> String'
54
+ RDL.type :Time, :tuesday?, '() -> %bool'
55
+ RDL.type :Time, :tv_nsec, '() -> Numeric'
56
+ RDL.type :Time, :tv_sec, '() -> Numeric'
57
+ RDL.type :Time, :tv_usec, '() -> Numeric'
58
+ RDL.type :Time, :usec, '() -> Numeric'
59
+ RDL.type :Time, :utc, '() -> self'
60
+ RDL.type :Time, :utc?, '() -> %bool'
61
+ RDL.type :Time, :utc_offset, '() -> Integer'
62
+ RDL.type :Time, :wday, '() -> Integer'
63
+ RDL.type :Time, :wednesday?, '() -> %bool'
64
+ RDL.type :Time, :yday, '() -> Integer'
65
+ RDL.type :Time, :year, '() -> Integer'
66
+ RDL.type :Time, :zone, '() -> String'
@@ -0,0 +1,18 @@
1
+ RDL.nowrap :URI
2
+
3
+ RDL.type :URI, :decode_www_form, '(String, ?Encoding, ?String separator, %bool use_charset, %bool isindex) -> Array<[String,String]>'
4
+ RDL.type :URI, :decode_www_form_component, '(String, ?Encoding) -> Array<[String,String]>'
5
+ # RDL.type :URI, :encode_www_form, '(Array<Array<String>>, ?) -> String' #Doublesplat
6
+ # RDL.type :URI, :encode_www_form_component, '(String, ?) -> String'
7
+ RDL.type :URI, :extract, '(String, ?Array) { (*%any) -> %any} -> Array<String>'
8
+ RDL.type :URI, :join, '(*String) -> URI::HTTP'
9
+ RDL.type :URI, :parse, '(String) -> URI::HTTP'
10
+ RDL.type :URI, :regexp, '(?Array schemes) -> Array<String>' #Assume schemes are strings
11
+ RDL.type :URI, :scheme_list, '() -> Hash<String,Class>'
12
+ RDL.type :URI, :split, '(String) -> Array<String or nil>'
13
+
14
+ RDL.type :URI, :escape, '(String, *Regexp) -> String'
15
+ RDL.type :URI, :escape, '(String, *String) -> String'
16
+ RDL.type :URI, :unescape, '(*String) -> String'
17
+ RDL.rdl_alias :URI, :encode, :escape
18
+ RDL.rdl_alias :URI, :decode, :unescape
@@ -0,0 +1,3 @@
1
+ RDL.nowrap :YAML
2
+
3
+ RDL.type :YAML, 'self.load_file', '(String) -> Array<String>'
@@ -0,0 +1 @@
1
+ Dir[File.dirname(__FILE__) + "/devise/**/*.rb"].each { |f| require f }
@@ -0,0 +1,3 @@
1
+ RDL.nowrap :'Devise::Controllers::Helpers'
2
+ RDL.type :'Devise::Controllers::Helpers', :devise_parameter_sanitizer, '() -> Devise::ParameterSanitizer'
3
+ RDL.type :'Devise::Controllers::Helpers', :current_user, '() -> User'
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'Devise::ParameterSanitizer'
2
+ RDL.type :'Devise::ParameterSanitizer', :permit, '(Symbol, Hash<Symbol, Array<Symbol>>) -> NilClass'
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :Pundit
2
+ RDL.type :Pundit, :authorize, '(%any, ?%any) -> %any'
@@ -0,0 +1,50 @@
1
+ # :integer, :bigint, :float, :decimal, :numeric, :datetime, :time, :date, :binary, :boolean.
2
+ # null allowed
3
+
4
+ RDL.type_alias '%symstr', 'Symbol or String'
5
+
6
+ class RDL::Rails
7
+
8
+ # [+ rails_type +] is a Rails column type (:string, :integer, etc)
9
+ # returns a String containing an RDL type
10
+ def self.column_to_rdl(rails_type)
11
+ case rails_type
12
+ when :string, :text, :binary
13
+ return 'String'
14
+ when :integer
15
+ return 'Fixnum'
16
+ when :float
17
+ return 'Float'
18
+ when :decimal
19
+ return 'BigDecimal'
20
+ when :boolean
21
+ return '%bool'
22
+ when :date
23
+ return 'Date'
24
+ when :time
25
+ return 'Time'
26
+ when :datetime
27
+ return 'DateTime'
28
+ else
29
+ raise RuntimeError, "Unrecoganized column type #{rails_type}"
30
+ end
31
+ end
32
+
33
+ # [+ model +] is an ActiveRecord::Base subclass that has been loaded.
34
+ # Gets the columns_hash of the model and returns a String that can
35
+ # serve as the paramter list to a method that accepts any number
36
+ # of the model's attributes keyed by the attribute names.
37
+ def self.attribute_types(model)
38
+ args = []
39
+
40
+ model.columns_hash.each { |name, col|
41
+ t = column_to_rdl(col.type)
42
+ if col.null
43
+ args << "#{name}: ?#{t}"
44
+ else
45
+ args << "#{name}: ?!#{t}"
46
+ end
47
+ }
48
+ return args.join ','
49
+ end
50
+ end
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'AbstractController::Translation'
2
+ RDL.type :'AbstractController::Translation', :t, '(Symbol or String) -> String'
@@ -0,0 +1,3 @@
1
+ RDL.nowrap :'ActionController::Base'
2
+ RDL.type :'ActionController::Base', 'self.helpers', '() -> ActionView::Base'
3
+ RDL.type :'ActionController::Base', :logger, '() -> ActiveSupport::TaggedLogging'
@@ -0,0 +1,6 @@
1
+ RDL.nowrap :'ActionController::Instrumentation'
2
+ RDL.type :'ActionController::Instrumentation', :render, '(String or Symbol) -> Array<String>'
3
+ RDL.type :'ActionController::Instrumentation', :render, '(?String or Symbol, {content_type: ?String, layout: ?%bool or String, action: ?String or Symbol, location: ?String, nothing: ?%bool, text: ?[to_s: () -> String], status: ?Symbol, content_type: ?String, formats: ?Symbol or Array<Symbol>, locals: ?Hash<Symbol, %any>}) -> Array<String>'
4
+ RDL.type :'ActionController::Instrumentation', :redirect_to, '(:back) -> String'
5
+ RDL.type :'ActionController::Instrumentation', :redirect_to, '({controller: ?String, action: ?String, notice: ?String, alert: ?String}) -> String'
6
+ RDL.type :'ActionController::Instrumentation', :redirect_to, '(String or Symbol or ActiveRecord::Base, ?{controller: ?String, action: ?String, notice: ?String, alert: ?String}) -> String'
@@ -0,0 +1,3 @@
1
+ RDL.nowrap :'ActionController::Metal'
2
+ RDL.type :'ActionController::Metal', :params, '() -> ActiveSupport::HashWithIndifferentAccess<String or Symbol, v>'
3
+ RDL.type :'ActionController::Metal', :request, '() -> ActionDispatch::Request'
@@ -0,0 +1,13 @@
1
+ RDL.type :'ActionController::MimeResponds', :respond_to,
2
+ '(*(String or Symbol)) { (ActionController::MimeResponds::Collector) -> %any } -> Array<String> or String'
3
+
4
+ module ActionController
5
+ module MimeResponds
6
+ class Collector
7
+ Mime::EXTENSION_LOOKUP.each { |mime|
8
+ RDL.type :'ActionController::MimeResponds::Collector', :method_missing,
9
+ "(#{mime[1].symbol.inspect}) { (ActionController::MimeResponds::Collector::VariantCollector) -> %any } -> %any"
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ RDL.nowrap :'ActionController::Parameters'
2
+ RDL.type :'ActionController::Parameters', :require, '(*Symbol) -> ActionController::Parameters'
3
+ RDL.type :'ActionController::Parameters', :permit, '(*Symbol) -> ActionController::Parameters'
@@ -8,15 +8,11 @@ class ActionController::Base
8
8
  def self.params_type(typs)
9
9
  # TODO: Ick, this is ugly. Once it's obvious how to generalize this kind of reasoning to other cases, clean this up!
10
10
  typs.each_pair { |param, param_type|
11
- param_type = $__rdl_parser.scan_str "#T #{param_type}"
12
- meth_type = $__rdl_parser.scan_str "(#{param.inspect}) -> #{param_type}" # given singleton symbol arg, get param's return type
13
- $__rdl_deferred << [self, :context_types, [ActionController::Parameters, :[], meth_type], class_check: self]
11
+ param_type = RDL::Globals.parser.scan_str "#T #{param_type}"
12
+ meth_type = RDL::Globals.parser.scan_str "(#{param.inspect}) -> #{param_type}" # given singleton symbol arg, get param's return type
13
+ RDL::Globals.deferred << [self, :context_types, [ActionController::Parameters, :[], meth_type], class_check: self]
14
14
  }
15
15
  end
16
16
  end
17
17
 
18
- module ActionController
19
- module StrongParameters
20
- type :params, '() -> ActionController::Parameters'
21
- end
22
- end
18
+ RDL.type :'ActionController::StrongParameters', :params, '() -> ActionController::Parameters'
@@ -0,0 +1,8 @@
1
+ RDL.nowrap :'ActionDispatch::Flash::FlashHash'
2
+ RDL.type :'ActionDispatch::Flash::FlashHash', :[], '(Symbol) -> String'
3
+ RDL.type :'ActionDispatch::Flash::FlashHash', :[]=, '(Symbol, String) -> String'
4
+ RDL.type :'ActionDispatch::Flash::FlashHash', :now, '() -> ActionDispatch::Flash::FlashNow'
5
+
6
+ RDL.nowrap :'ActionDispatch::Flash::FlashNow'
7
+ RDL.type :'ActionDispatch::Flash::FlashNow', :[], '(Symbol) -> String'
8
+ RDL.type :'ActionDispatch::Flash::FlashNow', :[]=, '(Symbol, String) -> String'
@@ -0,0 +1,10 @@
1
+ # module ActionDispatch
2
+ # module Routing
3
+ # class RouteSet
4
+ # post(:draw) { |ret|
5
+ # # puts "Routes are: #{Rails.application.routes.named_routes.helper_names}"
6
+ # true
7
+ # }
8
+ # end
9
+ # end
10
+ # end
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'ActionMailer::Base'
2
+ RDL.type :'ActionMailer::Base', :mail, '({subject: ?String, to: ?String, from: ?String, cc: ?String or Array<String>, bcc: ?String or Array<String>, reply_to: ?String, date: ?String}) -> Mail::Message'
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'ActionMailer::MessageDelivery'
2
+ RDL.type :'ActionMailer::MessageDelivery', :deliver_now, '() -> Mail::Message'
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'ActionView::Helpers::SanitizeHelper'
2
+ RDL.type :'ActionView::Helpers::SanitizeHelper', :strip_tags, '(String) -> String'
@@ -0,0 +1,5 @@
1
+ RDL.nowrap :'ActionView::Helpers::UrlHelper'
2
+ RDL.type :'ActionView::Helpers::UrlHelper', :link_to, '(String, String or ActiveRecord::Base, ?Hash<Symbol, %any>) -> ActiveSupport::SafeBuffer'
3
+ RDL.type :'ActionView::Helpers::UrlHelper', :link_to, '(String, ?Hash<Symbol, %any>, ?Hash<Symbol, %any>) -> ActiveSupport::SafeBuffer'
4
+ RDL.type :'ActionView::Helpers::UrlHelper', :link_to, '(?Hash<Symbol, %any>, ?Hash<Symbol, %any>) {() -> String} -> ActiveSupport::SafeBuffer'
5
+ RDL.type :'ActionView::Helpers::UrlHelper', :link_to, '(?String, ?Hash<Symbol, %any>) {() -> String} -> ActiveSupport::SafeBuffer'
@@ -0,0 +1,14 @@
1
+ RDL.nowrap :'ActiveModel::Errors'
2
+ RDL.type :'ActiveModel::Errors', :clear, '() -> %any'
3
+ RDL.type :'ActiveModel::Errors', :delete, '(%symstr) -> %any'
4
+ RDL.type :'ActiveModel::Errors', :[], '(%symstr) -> Array<String>'
5
+ RDL.type :'ActiveModel::Errors', :each, '() { (%symstr, String) -> %any } -> %any'
6
+ RDL.type :'ActiveModel::Errors', :size, '() -> Integer'
7
+ RDL.rdl_alias :'ActiveModel::Errors', :count, :size
8
+ RDL.type :'ActiveModel::Errors', :values, '() -> Array<String>'
9
+ RDL.type :'ActiveModel::Errors', :keys, '() -> Array<Symbol>'
10
+ RDL.type :'ActiveModel::Errors', :empty?, '() -> %bool'
11
+ RDL.rdl_alias :'ActiveModel::Errors', :blank?, :empty?
12
+ RDL.type :'ActiveModel::Errors', :hash, '(?%bool full_messages) -> Hash<Symbol, String>'
13
+ RDL.type :'ActiveModel::Errors', :add, '(%symstr, %symstr, Hash<Symbol, %any>) -> %any'
14
+ RDL.type :'ActiveModel::Errors', :add, '(%symstr, { () -> String }, Hash<Symbol, %any>) -> %any' # TODO: combine with prev with union once supported
@@ -0,0 +1,2 @@
1
+ RDL.nowrap :'ActiveModel::Validations'
2
+ RDL.type :'ActiveModel::Validations', :errors, '() -> ActiveModel::Errors'
@@ -0,0 +1,208 @@
1
+ RDL.nowrap :'ActiveRecord::Associations::CollectionProxy'
2
+
3
+ RDL.type_params :'ActiveRecord::Associations::CollectionProxy', [:t], :all?
4
+
5
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :<<, '(*(t or Array<t>)) -> self'
6
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :==, '(%any) -> %bool'
7
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :any?, '() ?{ (t) -> %bool } -> %bool'
8
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :append, :<<
9
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :build, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
10
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :clear, '() -> self'
11
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :concat, '(*t) -> self'
12
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :count, '() -> Integer'
13
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :create, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
14
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :create!, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
15
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :delete, '(*t) -> Array<t>'
16
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :delete_all, '(?Symbol dependent) -> Array<t>'
17
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :destroy, '(*t) -> Array<t>'
18
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :destroy_all, '() -> %any'
19
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :distinct, '() -> self'
20
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :empty?, '() -> %bool'
21
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :find, '(Integer) -> t'
22
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :find, '(Integer, Integer, *Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
23
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :include?, '(t) -> %bool'
24
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :length, '() -> Integer'
25
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :load_target, '() -> %any'
26
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :loaded?, '() -> %bool'
27
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :many?, '() ?{ (t) -> %bool } -> %bool'
28
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :new, :build
29
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :push, :<<
30
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :reload, '() -> self'
31
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :replace, '(Array<t>) -> %any'
32
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :reset, '() -> self'
33
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :scope, '() -> ActiveRecord::Relation' # TODO fix
34
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :select, '(*Symbol) -> t'
35
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :select, '() { (t) -> %bool } -> ActiveRecord::Associations::CollectionProxy<t>'
36
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :size, '() -> Integer'
37
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :spawn, :scope
38
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :take, '() -> t or nil'
39
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :take, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
40
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :to_ary, '() -> Array<t>'
41
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :to_a, :to_ary
42
+ RDL.rdl_alias :'ActiveRecord::Associations::CollectionProxy', :unique, :distinct
43
+
44
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :first, '() -> t or nil'
45
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :first, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
46
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :second, '() -> t or nil'
47
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :second, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
48
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :third, '() -> t or nil'
49
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :third, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
50
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :fourth, '() -> t or nil'
51
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :fourth, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
52
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :fifth, '() -> t or nil'
53
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :fifth, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
54
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :forty_two, '() -> t or nil'
55
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :forty_two, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
56
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :third_to_last, '() -> t or nil'
57
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :third_to_last, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
58
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :second_to_last, '() -> t or nil'
59
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :second_to_last, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
60
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :last, '() -> t or nil'
61
+ RDL.type :'ActiveRecord::Associations::CollectionProxy', :last, '(Integer) -> ActiveRecord::Associations::CollectionProxy<t>'
62
+
63
+ module ActiveRecord::Associations::ClassMethods
64
+
65
+ # TODO: Check presence of methods required by, e.g., foreign_key, primary_key, etc.
66
+ # TODO: Check counter_cache, add to model attr_readonly_type
67
+
68
+ extend RDL::RDLAnnotate
69
+
70
+ rdl_type :'ActiveRecord::Associations::ClassMethods', :belongs_to,
71
+ '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr, foreign_key: ?%symstr,' +
72
+ 'primary_key: ?%symstr, dependent: ?(:delete or :destroy), counter_cache: ?(%bool or %symstr),' +
73
+ 'polymorphic: ?%bool, validate: ?%bool, autosave: ?%bool, touch: ?(%bool or %symstr),' +
74
+ 'inverse_of: ?%symstr, optional: ?%bool, required: ?%bool, anonymous_class: ?Class) -> %any'
75
+
76
+ rdl_pre :'ActiveRecord::Associations::ClassMethods', :belongs_to do
77
+ |name, scope=nil, class_name: nil, foreign_key: nil, primary_key: nil,
78
+ dependent: nil, counter_cache: nil, polymorphic: nil,
79
+ validate: nil, autosave: nil, touch: nil, inverse_of: nil,
80
+ optional: nil, required: nil, anonymous_class: nil|
81
+
82
+ if polymorphic
83
+ assoc_type = '%any' # type is data-driven, can't determine statically
84
+ elsif class_name
85
+ assoc_type = class_name.to_s.classify
86
+ elsif anonymous_class
87
+ assoc_type = anonymous_class.to_s
88
+ else
89
+ assoc_type = name.to_s.classify # camelize?
90
+ end
91
+ rdl_type name, "(?%bool force_reload) -> #{assoc_type}"
92
+ rdl_type "#{name}=", "(#{assoc_type}) -> #{assoc_type}"
93
+ unless polymorphic
94
+ RDL.at(:model) { |sym|
95
+ assoc_attribute_types = RDL::Rails.attribute_types(assoc_type.constantize)
96
+ rdl_type "build_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
97
+ rdl_type "create_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
98
+ rdl_type "create_#{name}!", "(#{assoc_attribute_types}) -> #{assoc_type}"
99
+ }
100
+ end
101
+ true
102
+ end
103
+
104
+ rdl_type :'ActiveRecord::Associations::ClassMethods', :has_one,
105
+ '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,'+
106
+ 'dependent: ?(:destroy or :delete or :nullify or :restrict_with_exception or :restrict_with_error),' +
107
+ 'foreign_key: ?%symstr, foreign_type: ?%symstr, primary_key: ?%symstr, as: ?%symstr,' +
108
+ 'through: ?%symstr, source: ?%symstr, source_type: ?%symstr, validate: ?%bool, autosave: ?%bool,' +
109
+ 'inverse_of: ?%symstr, required: ?%bool, anonymous_class: ?Class) -> %any'
110
+
111
+ rdl_pre :'ActiveRecord::Associations::ClassMethods', :has_one do
112
+ |name, scope=nil, class_name: nil, dependent: nil, foreign_key: nil,
113
+ foreign_type: nil, primary_key: nil, as: nil, through: nil, source: nil,
114
+ source_type: nil, vadliate: nil, autosave: nil, inverse_of: nil,
115
+ required: nil|
116
+
117
+ if as
118
+ assoc_type = '%any' # type is data-driven, can't determine statically
119
+ elsif class_name
120
+ assoc_type = class_name.to_s.classify
121
+ elsif anonymous_class # not sure this has anonymou_class
122
+ assoc_type = anonymous_class.to_s.classify
123
+ else
124
+ assoc_type = name.to_s.classify # camelize?
125
+ end
126
+ rdl_type name, "(?%bool force_reload) -> #{assoc_type}"
127
+ rdl_type "#{name}=", "(#{assoc_type}) -> #{assoc_type}"
128
+ unless as
129
+ RDL.at(:model) { |sym|
130
+ assoc_attribute_types = RDL::Rails.attribute_types(assoc_type.constantize)
131
+ rdl_type "build_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
132
+ rdl_type "create_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
133
+ rdl_type "create_#{name}!", "(#{assoc_attribute_types}) -> #{assoc_type}"
134
+ }
135
+ end
136
+ end
137
+
138
+ rdl_type :'ActiveRecord::Associations::ClassMethods', :has_many,
139
+ '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,' +
140
+ 'foreign_key: ?%symstr, foreign_type: ?%symstr, primary_key: ?%symstr,' +
141
+ 'dependent: ?(:destroy or :delete_all or :nullify or :restrict_with_exception or :restrict_with_error),' +
142
+ 'counter_cache: ?(%bool or %symstr), as: ?%symstr, through: ?%symstr, source: ?%symstr,' +
143
+ 'source_type: ?%symstr, validate: ?%bool, inverse_of: ?%symstr, extend: ?(Module or Array<Module>))' +
144
+ '?{ () -> %any } -> %any'
145
+
146
+ rdl_pre :'ActiveRecord::Associations::ClassMethods', :has_many do
147
+ |name, scope=nil, class_name: nil, foreign_key: nil, foreign_type: nil, primary_key: nil,
148
+ dependent: nil, counter_cache: nil, as: nil, through: nil, source: nil, source_type: nil,
149
+ validate: nil, inverse_of: nil, extend: nil|
150
+
151
+ if class_name
152
+ collect_type = class_name.to_s.classify
153
+ else
154
+ collect_type = name.to_s.singularize.classify
155
+ end
156
+ rdl_type name, "() -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>"
157
+ rdl_type "#{name}=", "(Array<t>) -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>" # TODO not sure of type
158
+ RDL.at(:model) {
159
+ # primary_key is not available when has_many is first called!
160
+ id_type = RDL::Rails.column_to_rdl(collect_type.constantize.columns_hash[primary_key].type)
161
+ rdl_type "#{name.to_s.singularize}_ids", "() -> Array<#{id_type}>"
162
+ rdl_type "#{name.to_s.singularize}_ids=", "() -> Array<#{id_type}>"
163
+ }
164
+ true
165
+ end
166
+
167
+ rdl_type :'ActiveRecord::Associations::ClassMethods', :has_and_belongs_to_many,
168
+ '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,' +
169
+ 'join_table: ?%symstr, foreign_key: ?%symstr, association_foreign_key: ?%symstr,' +
170
+ 'validate: ?%bool, autosave: ?%bool) ?{ () -> %any } -> %any'
171
+
172
+ rdl_pre :'ActiveRecord::Associations::ClassMethods', :has_and_belongs_to_many do
173
+ |name, scope=nil, class_name: nil, join_table: nil,
174
+ foreign_key: nil, association_foreign_key: nil,
175
+ validate: nil, autosave: nil|
176
+
177
+ if class_name
178
+ collect_type = class_name.to_s.classify
179
+ else
180
+ collect_type = name.to_s.singularize.classify
181
+ end
182
+ rdl_type name, "() -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>"
183
+ rdl_type "#{name}=", "(Array<t>) -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>" # TODO not sure of type
184
+ RDL.at(:model) {
185
+ # primary_key is not available when has_and_belongs_to_many is first called!
186
+ id_type = RDL::Rails.column_to_rdl(collect_type.constantize.columns_hash[primary_key].type)
187
+ rdl_type "#{name.to_s.singularize}_ids", "() -> Array<#{id_type}>"
188
+ rdl_type "#{name.to_s.singularize}_ids=", "() -> Array<#{id_type}>"
189
+ }
190
+
191
+ # Remaining methods are from CollectionProxy
192
+ # TODO give these precise types for this particular model
193
+ # collection<<(object, ...)
194
+ # collection.delete(object, ...)
195
+ # collection.destroy(object, ...)
196
+ # collection.clear
197
+ # collection.empty?
198
+ # collection.size
199
+ # collection.find(...)
200
+ # collection.where(...)
201
+ # collection.exists?(...)
202
+ # collection.build(attributes = {})
203
+ # collection.create(attributes = {})
204
+ # collection.create!(attributes = {})
205
+ true
206
+ end
207
+
208
+ end