rdl 2.0.1 → 2.1.0

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 (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
@@ -1,7 +0,0 @@
1
- class StringScanner
2
- rdl_nowrap
3
-
4
- type :eos?, '() -> %bool'
5
- type :scan, '(Regexp) -> String'
6
- type :getch, '() -> String'
7
- end
@@ -1,29 +0,0 @@
1
- class Symbol
2
- rdl_nowrap
3
-
4
- type 'self.all_symbols', '() -> Array<Symbol>'
5
- type :<=>, '(Symbol other) -> Fixnum or nil'
6
- type :==, '(%any obj) -> %bool'
7
- type :=~, '(%any obj) -> Fixnum or nil'
8
- type :[], '(Fixnum idx) -> String'
9
- type :[], '(Fixnum b, Fixnum n) -> String'
10
- type :[], '(Range<Fixnum>) -> String'
11
- type :capitalize, '() -> Symbol'
12
- type :casecmp, '(Symbol other) -> Fixnum or nil'
13
- type :downcase, '() -> Symbol'
14
- type :empty?, '() -> %bool'
15
- type :encoding, '() -> Encoding'
16
- type :id2name, '() -> String'
17
- type :inspect, '() -> String'
18
- type :intern, '() -> self'
19
- type :length, '() -> Fixnum'
20
- type :match, '(%any obj) -> Fixnum or nil'
21
- type :succ, '() -> Symbol'
22
- rdl_alias :size, :length
23
- rdl_alias :slice, :[]
24
- type :swapcase, '() -> Symbol'
25
- type :to_proc, '() -> Proc' # TODO proc
26
- rdl_alias :to_s, :id2name
27
- rdl_alias :to_sym, :intern
28
- type :upcase, '() -> Symbol'
29
- end
@@ -1,68 +0,0 @@
1
- class Time
2
- rdl_nowrap
3
-
4
- type 'self.at', '(Time) -> Time'
5
- type 'self.at', '(Numeric seconds_with_frac) -> Time'
6
- type 'self.at', '(Numeric seconds, Numeric microseconds_with_frac) -> Time'
7
- type 'self.gm', '(Fixnum year, ?(Fixnum or String) month, ?Fixnum day, ?Fixnum hour, ?Fixnum min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
8
- type 'self.local', '(Fixnum year, ?(Fixnum or String) month, ?Fixnum day, ?Fixnum hour, ?Fixnum min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
9
- rdl_alias 'self.mktime', 'self.local'
10
- type 'self.new', '(?Fixnum year, ?(Fixnum or String) month, ?Fixnum day, ?Fixnum hour, ?Fixnum min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
11
- type 'self.now', '() -> Time'
12
- type 'self.utc', '(Fixnum year, ?(Fixnum or String) month, ?Fixnum day, ?Fixnum hour, ?Fixnum min, ?Numeric sec, ?Numeric usec_with_frac) -> Time'
13
-
14
- type :+, '(Numeric) -> Time'
15
- type :-, '(Time) -> Float'
16
- type :-, '(Numeric) -> Time'
17
- type :<=>, '(Time other) -> -1 or 0 or 1 or nil'
18
- type :asctime, '() -> String'
19
- type :ctime, '() -> String'
20
- type :day, '() -> Fixnum'
21
- type :dst?, '() -> %bool'
22
- type :eql?, '(%any) -> %bool'
23
- type :friday?, '() -> %bool'
24
- type :getgm, '() -> Time'
25
- type :getlocal, '(?Fixnum utc_offset) -> Time'
26
- type :getutc, '() -> Time'
27
- type :gmt?, '() -> %bool'
28
- type :gmt_offset, '() -> Fixnum'
29
- type :gmtime, '() -> self'
30
- rdl_alias :gmtoff, :gmt_offset
31
- type :hash, '() -> Fixnum'
32
- type :hour, '() -> Fixnum'
33
- type :inspect, '() -> String'
34
- type :isdst, '() -> %bool'
35
- type :localtime, '(?String utc_offset) -> self'
36
- type :mday, '() -> Fixnum'
37
- type :min, '() -> Fixnum'
38
- type :mon, '() -> Fixnum'
39
- type :monday?, '() -> %bool'
40
- rdl_alias :month, :mon
41
- type :nsec, '() -> Fixnum'
42
- type :round, '(Fixnum) -> Time'
43
- type :saturday, '() -> %bool'
44
- type :sec, '() -> Fixnum'
45
- type :strftime, '(String) -> String'
46
- type :subsec, '() -> Numeric'
47
- type :succ, '() -> Time'
48
- type :sunday?, '() -> %bool'
49
- type :thursday?, '() -> %bool'
50
- type :to_a, '() -> [Fixnum, Fixnum, Fixnum, Fixnum, Fixnum, Fixnum, Fixnum, Fixnum, %bool, String]'
51
- type :to_f, '() -> Float'
52
- type :to_i, '() -> Numeric'
53
- type :to_r, '() -> Rational'
54
- type :to_s, '() -> String'
55
- type :tuesday?, '() -> %bool'
56
- type :tv_nsec, '() -> Numeric'
57
- type :tv_sec, '() -> Numeric'
58
- type :tv_usec, '() -> Numeric'
59
- type :usec, '() -> Numeric'
60
- type :utc, '() -> self'
61
- type :utc?, '() -> %bool'
62
- type :utc_offset, '() -> Fixnum'
63
- type :wday, '() -> Fixnum'
64
- type :wednesday?, '() -> %bool'
65
- type :yday, '() -> Fixnum'
66
- type :year, '() -> Fixnum'
67
- type :zone, '() -> String'
68
- end
@@ -1,20 +0,0 @@
1
- module URI
2
- rdl_nowrap
3
-
4
- type :decode_www_form, '(String, ?Encoding, ?String separator, %bool use_charset, %bool isindex) -> Array<[String,String]>'
5
- type :decode_www_form_component, '(String, ?Encoding) -> Array<[String,String]>'
6
- # type 'encode_www_form', '(Array<Array<String>>, ?) -> String' #Doublesplat
7
- # type 'encode_www_form_component', '(String, ?) -> String'
8
- type :extract, '(String, ?Array) { (*%any) -> %any} -> Array<String>'
9
- type :join, '(*String) -> URI::HTTP'
10
- type :parse, '(String) -> URI::HTTP'
11
- type :regexp, '(?Array schemes) -> Array<String>' #Assume schemes are strings
12
- type :scheme_list, '() -> Hash<String,Class>'
13
- type :split, '(String) -> Array<String or nil>'
14
-
15
- type :escape, '(String, *Regexp) -> String'
16
- type :escape, '(String, *String) -> String'
17
- type :unescape, '(*String) -> String'
18
- rdl_alias :encode, :escape
19
- rdl_alias :decode, :unescape
20
- end
@@ -1,5 +0,0 @@
1
- module YAML
2
- rdl_nowrap
3
-
4
- type 'self.load_file', '(String) -> Array<String>'
5
- end
@@ -1,52 +0,0 @@
1
- # :integer, :bigint, :float, :decimal, :numeric, :datetime, :time, :date, :binary, :boolean.
2
- # null allowed
3
-
4
- type_alias '%symstr', 'Symbol or String'
5
-
6
- module RDL
7
- class Rails
8
-
9
- # [+ rails_type +] is a Rails column type (:string, :integer, etc)
10
- # returns a String containing an RDL type
11
- def self.column_to_rdl(rails_type)
12
- case rails_type
13
- when :string, :text, :binary
14
- return 'String'
15
- when :integer
16
- return 'Fixnum'
17
- when :float
18
- return 'Float'
19
- when :decimal
20
- return 'BigDecimal'
21
- when :boolean
22
- return '%bool'
23
- when :date
24
- return 'Date'
25
- when :time
26
- return 'Time'
27
- when :datetime
28
- return 'DateTime'
29
- else
30
- raise RuntimeError, "Unrecoganized column type #{rails_type}"
31
- end
32
- end
33
-
34
- # [+ model +] is an ActiveRecord::Base subclass that has been loaded.
35
- # Gets the columns_hash of the model and returns a String that can
36
- # serve as the paramter list to a method that accepts any number
37
- # of the model's attributes keyed by the attribute names.
38
- def self.attribute_types(model)
39
- args = []
40
-
41
- model.columns_hash.each { |name, col|
42
- t = column_to_rdl(col.type)
43
- if col.null
44
- args << "#{name}: ?#{t}"
45
- else
46
- args << "#{name}: ?!#{t}"
47
- end
48
- }
49
- return args.join ','
50
- end
51
- end
52
- end
@@ -1,11 +0,0 @@
1
- module ActionController
2
- module MimeResponds
3
- type :respond_to, '(*(String or Symbol)) { (ActionController::MimeResponds::Collector) -> %any } -> Array<String> or String'
4
-
5
- class Collector
6
- Mime::EXTENSION_LOOKUP.each { |mime|
7
- type :method_missing, "(#{mime[1].symbol.inspect}) { (ActionController::MimeResponds::Collector::VariantCollector) -> %any } -> %any"
8
- }
9
- end
10
- end
11
- end
@@ -1,10 +0,0 @@
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
@@ -1,15 +0,0 @@
1
- class ActiveModel::Errors
2
- type :clear, '() -> %any'
3
- type :delete, '(%symstr) -> %any'
4
- type :[], '(%symstr) -> Array<String>'
5
- type :each, '() { (%symstr, String) -> %any } -> %any'
6
- type :size, '() -> %integer'
7
- rdl_alias :count, :size
8
- type :values, '() -> Array<String>'
9
- type :keys, '() -> Array<Symbol>'
10
- type :empty?, '() -> %bool'
11
- rdl_alias :blank?, :empty?
12
- type :hash, '(?%bool full_messages) -> Hash<Symbol, String>'
13
- type :add, '(%symstr, %symstr, Hash<Symbol, %any>) -> %any'
14
- type :add, '(%symstr, { () -> String }, Hash<Symbol, %any>) -> %any' # TODO: combine with prev with union once supported
15
- end
@@ -1,5 +0,0 @@
1
- module ActiveModel
2
- module Validations
3
- type :errors, '() -> ActiveModel::Errors'
4
- end
5
- end
@@ -1,190 +0,0 @@
1
- class ActiveRecord::Associations::CollectionProxy
2
- type_params [:t], :all?
3
-
4
- type :<<, '(*(t or Array<t>)) -> self'
5
- type :==, '(%any) -> %bool'
6
- type :any?, '() ?{ (t) -> %bool } -> %bool'
7
- rdl_alias :append, :<<
8
- type :build, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
9
- type :clear, '() -> self'
10
- type :concat, '(*t) -> self'
11
- type :count, '() -> %integer'
12
- type :create, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
13
- type :create!, '(Hash<Symbol, %any> or Array<Hash<Symbol, %any>>) -> self'
14
- type :delete, '(*t) -> Array<t>'
15
- type :delete_all, '(?Symbol dependent) -> Array<t>'
16
- type :destroy, '(*t) -> Array<t>'
17
- type :destroy_all, '() -> %any'
18
- type :distinct, '() -> self'
19
- type :empty?, '() -> %bool'
20
- type :find, '(%integer) -> t'
21
- type :find, '(%integer, %integer, *%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
22
- type :include?, '(t) -> %bool'
23
- type :length, '() -> %integer'
24
- type :load_target, '() -> %any'
25
- type :loaded?, '() -> %bool'
26
- type :many?, '() ?{ (t) -> %bool } -> %bool'
27
- rdl_alias :new, :build
28
- rdl_alias :push, :<<
29
- type :reload, '() -> self'
30
- type :replace, '(Array<t>) -> %any'
31
- type :reset, '() -> self'
32
- type :scope, '() -> ActiveRecord::Relation' # TODO fix
33
- type :select, '(*Symbol) -> t'
34
- type :select, '() { (t) -> %bool } -> ActiveRecord::Associations::CollectionProxy<t>'
35
- type :size, '() -> %integer'
36
- rdl_alias :spawn, :scope
37
- type :take, '() -> t or nil'
38
- type :take, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
39
- type :to_ary, '() -> Array<t>'
40
- rdl_alias :to_a, :to_ary
41
- rdl_alias :unique, :distinct
42
-
43
- type :first, '() -> t or nil'
44
- type :first, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
45
- type :second, '() -> t or nil'
46
- type :second, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
47
- type :third, '() -> t or nil'
48
- type :third, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
49
- type :fourth, '() -> t or nil'
50
- type :fourth, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
51
- type :fifth, '() -> t or nil'
52
- type :fifth, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
53
- type :forty_two, '() -> t or nil'
54
- type :forty_two, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
55
- type :third_to_last, '() -> t or nil'
56
- type :third_to_last, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
57
- type :second_to_last, '() -> t or nil'
58
- type :second_to_last, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
59
- type :last, '() -> t or nil'
60
- type :last, '(%integer) -> ActiveRecord::Associations::CollectionProxy<t>'
61
- end
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
-
69
- type :belongs_to, '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr, foreign_key: ?%symstr,' +
70
- 'primary_key: ?%symstr, dependent: ?(:delete or :destroy), counter_cache: ?(%bool or %symstr),' +
71
- 'polymorphic: ?%bool, validate: ?%bool, autosave: ?%bool, touch: ?(%bool or %symstr),' +
72
- 'inverse_of: ?%symstr, optional: ?%bool, required: ?%bool, anonymous_class: ?Class) -> %any'
73
-
74
- pre :belongs_to do |name, scope=nil, class_name: nil, foreign_key: nil, primary_key: nil,
75
- dependent: nil, counter_cache: nil, polymorphic: nil,
76
- validate: nil, autosave: nil, touch: nil, inverse_of: nil,
77
- optional: nil, required: nil, anonymous_class: nil|
78
- if polymorphic
79
- assoc_type = '%any' # type is data-driven, can't determine statically
80
- elsif class_name
81
- assoc_type = class_name.to_s.classify
82
- elsif anonymous_class
83
- assoc_type = anonymous_class.to_s
84
- else
85
- assoc_type = name.to_s.classify # camelize?
86
- end
87
- type name, "(?%bool force_reload) -> #{assoc_type}"
88
- type "#{name}=", "(#{assoc_type}) -> #{assoc_type}"
89
- unless polymorphic
90
- rdl_at(:model) { |sym|
91
- assoc_attribute_types = RDL::Rails.attribute_types(assoc_type.constantize)
92
- type "build_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
93
- type "create_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
94
- type "create_#{name}!", "(#{assoc_attribute_types}) -> #{assoc_type}"
95
- }
96
- end
97
- true
98
- end
99
-
100
- type :has_one, '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,'+
101
- 'dependent: ?(:destroy or :delete or :nullify or :restrict_with_exception or :restrict_with_error),' +
102
- 'foreign_key: ?%symstr, foreign_type: ?%symstr, primary_key: ?%symstr, as: ?%symstr,' +
103
- 'through: ?%symstr, source: ?%symstr, source_type: ?%symstr, validate: ?%bool, autosave: ?%bool,' +
104
- 'inverse_of: ?%symstr, required: ?%bool, anonymous_class: ?Class) -> %any'
105
-
106
- pre :has_one do |name, scope=nil, class_name: nil, dependent: nil, foreign_key: nil,
107
- foreign_type: nil, primary_key: nil, as: nil, through: nil, source: nil,
108
- source_type: nil, vadliate: nil, autosave: nil, inverse_of: nil,
109
- required: nil|
110
- if as
111
- assoc_type = '%any' # type is data-driven, can't determine statically
112
- elsif class_name
113
- assoc_type = class_name.to_s.classify
114
- elsif anonymous_class # not sure this has anonymou_class
115
- assoc_type = anonymous_class.to_s.classify
116
- else
117
- assoc_type = name.to_s.classify # camelize?
118
- end
119
- type name, "(?%bool force_reload) -> #{assoc_type}"
120
- type "#{name}=", "(#{assoc_type}) -> #{assoc_type}"
121
- unless as
122
- rdl_at(:model) { |sym|
123
- assoc_attribute_types = RDL::Rails.attribute_types(assoc_type.constantize)
124
- type "build_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
125
- type "create_#{name}", "(#{assoc_attribute_types}) -> #{assoc_type}"
126
- type "create_#{name}!", "(#{assoc_attribute_types}) -> #{assoc_type}"
127
- }
128
- end
129
- end
130
-
131
- type :has_many, '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,' +
132
- 'foreign_key: ?%symstr, foreign_type: ?%symstr, primary_key: ?%symstr,' +
133
- 'dependent: ?(:destroy or :delete_all or :nullify or :restrict_with_exception or :restrict_with_error),' +
134
- 'counter_cache: ?(%bool or %symstr), as: ?%symstr, through: ?%symstr, source: ?%symstr,' +
135
- 'source_type: ?%symstr, validate: ?%bool, inverse_of: ?%symstr, extend: ?(Module or Array<Module>))' +
136
- '?{ () -> %any } -> %any'
137
-
138
- pre :has_many do |name, scope=nil, class_name: nil, foreign_key: nil, foreign_type: nil, primary_key: nil,
139
- dependent: nil, counter_cache: nil, as: nil, through: nil, source: nil, source_type: nil,
140
- validate: nil, inverse_of: nil, extend: nil|
141
- if class_name
142
- collect_type = class_name.to_s.classify
143
- else
144
- collect_type = name.to_s.singularize.classify
145
- end
146
- type name, "() -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>"
147
- type "#{name}=", "(Array<t>) -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>" # TODO not sure of type
148
- id_type = RDL::Rails.column_to_rdl(collect_type.constantize.columns_hash['id'].type) # TODO assumes id field is "id"
149
- type "#{name.to_s.singularize}_ids", "() -> Array<#{id_type}>"
150
- type "#{name.to_s.singularize}_ids=", "() -> Array<#{id_type}>"
151
-
152
- true
153
- end
154
-
155
- type :has_and_belongs_to_many, '(%symstr name, ?{ (?ActiveRecord::Base) -> %any } scope, class_name: ?%symstr,' +
156
- 'join_table: ?%symstr, foreign_key: ?%symstr, association_foreign_key: ?%symstr,' +
157
- 'validate: ?%bool, autosave: ?%bool) ?{ () -> %any } -> %any'
158
-
159
- pre :has_and_belongs_to_many do |name, scope=nil, class_name: nil, join_table: nil,
160
- foreign_key: nil, association_foreign_key: nil,
161
- validate: nil, autosave: nil|
162
- if class_name
163
- collect_type = class_name.to_s.classify
164
- else
165
- collect_type = name.to_s.singularize.classify
166
- end
167
- type name, "() -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>"
168
- type "#{name}=", "(Array<t>) -> ActiveRecord::Associations::CollectionProxy<#{collect_type}>" # TODO not sure of type
169
- id_type = RDL::Rails.column_to_rdl(collect_type.constantize.columns_hash['id'].type) # TODO assumes id field is "id"
170
- type "#{name.to_s.singularize}_ids", "() -> Array<#{id_type}>"
171
- type "#{name.to_s.singularize}_ids=", "() -> Array<#{id_type}>"
172
-
173
- # Remaining methods are from CollectionProxy
174
- # TODO give these precise types for this particular model
175
- # collection<<(object, ...)
176
- # collection.delete(object, ...)
177
- # collection.destroy(object, ...)
178
- # collection.clear
179
- # collection.empty?
180
- # collection.size
181
- # collection.find(...)
182
- # collection.where(...)
183
- # collection.exists?(...)
184
- # collection.build(attributes = {})
185
- # collection.create(attributes = {})
186
- # collection.create!(attributes = {})
187
- true
188
- end
189
-
190
- end
@@ -1,3 +0,0 @@
1
- module ActiveRecord::Core
2
- type :==, '(%any) -> %bool'
3
- end
@@ -1,39 +0,0 @@
1
- module ActiveRecord
2
- module ModelSchema
3
- module ClassMethods
4
- post(:load_schema!) { |ret| # load_schema! doesn't return anything interesting
5
- columns_hash.each { |name, col|
6
- t = RDL::Rails.column_to_rdl(col.type)
7
- if col.null
8
- # may be null; show nullability in return type
9
- type name, "() -> #{t} or nil" # getter
10
- type "#{name}=", "(#{t}) -> #{t} or nil" # setter
11
- type "write_attribute", "(:#{name}, #{t}) -> %bool"
12
- type "update_attribute", "(:#{name}, #{t}) -> %bool"
13
- type "update_column", "(:#{name}, #{t}) -> %bool"
14
- else
15
- # not null; can't truly check in type system but hint via the name
16
- type name, "() -> !#{t}" # getter
17
- type "#{name}=", "(!#{t}) -> !#{t}" # setter
18
- type "write_attribute", "(:#{name}, !#{t}) -> %bool"
19
- type "update_attribute", "(:#{name}, #{t}) -> %bool"
20
- type "update_column", "(:#{name}, #{t}) -> %bool"
21
- end
22
- }
23
-
24
- attribute_types = RDL::Rails.attribute_types(self)
25
- type 'self.find_by', '(' + attribute_types + ") -> #{self} or nil"
26
- type 'self.find_by!', '(' + attribute_types + ") -> #{self}"
27
- type 'update', '(' + attribute_types + ') -> %bool'
28
- type 'update_columns', '(' + attribute_types + ') -> %bool'
29
- type 'attributes=', '(' + attribute_types + ') -> %bool'
30
-
31
- # If called with String arguments, can't check types as precisely
32
- type 'write_attribute', '(String, %any) -> %bool'
33
- type 'update_attribute', '(String, %any) -> %bool'
34
- type 'update_column', '(String, %any) -> %bool'
35
- true
36
- }
37
- end
38
- end
39
- end