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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/CHANGES.md +35 -0
- data/README.md +153 -116
- data/bin/rdl_query +1 -1
- data/extras/type_tests/typetests.rb +905 -0
- data/lib/rdl.rb +0 -1
- data/lib/rdl/boot.rb +108 -77
- data/lib/rdl/boot_rails.rb +2 -8
- data/lib/rdl/config.rb +44 -17
- data/lib/rdl/contracts/flat.rb +1 -1
- data/lib/rdl/info.rb +3 -3
- data/lib/rdl/query.rb +11 -11
- data/lib/rdl/typecheck.rb +399 -136
- data/lib/rdl/types/finite_hash.rb +3 -2
- data/lib/rdl/types/generic.rb +7 -6
- data/lib/rdl/types/intersection.rb +3 -2
- data/lib/rdl/types/lexer.rex +2 -3
- data/lib/rdl/types/lexer.rex.rb +1 -4
- data/lib/rdl/types/method.rb +7 -6
- data/lib/rdl/types/nominal.rb +10 -1
- data/lib/rdl/types/parser.racc +7 -8
- data/lib/rdl/types/parser.tab.rb +108 -109
- data/lib/rdl/types/structural.rb +1 -0
- data/lib/rdl/types/tuple.rb +2 -2
- data/lib/rdl/types/type.rb +8 -8
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +2 -1
- data/lib/rdl/util.rb +28 -3
- data/lib/rdl/wrap.rb +216 -165
- data/lib/rdl_disable.rb +22 -15
- data/lib/types/core.rb +2 -4
- data/lib/types/core/_aliases.rb +14 -0
- data/lib/types/core/abbrev.rb +3 -0
- data/lib/types/core/array.rb +139 -0
- data/lib/types/core/base64.rb +8 -0
- data/lib/types/core/basic_object.rb +12 -0
- data/lib/types/core/benchmark.rb +9 -0
- data/lib/types/core/bigdecimal.rb +223 -0
- data/lib/types/core/bigmath.rb +10 -0
- data/lib/types/core/bignum.rb +214 -0
- data/lib/types/core/class.rb +15 -0
- data/lib/types/core/complex.rb +123 -0
- data/lib/types/core/coverage.rb +4 -0
- data/lib/types/core/csv.rb +3 -0
- data/lib/types/core/date.rb +4 -0
- data/lib/types/core/dir.rb +37 -0
- data/lib/types/core/encoding.rb +21 -0
- data/lib/types/core/enumerable.rb +96 -0
- data/lib/types/core/enumerator.rb +24 -0
- data/lib/types/core/exception.rb +15 -0
- data/lib/types/core/file.rb +125 -0
- data/lib/types/core/fileutils.rb +4 -0
- data/lib/types/core/fixnum.rb +213 -0
- data/lib/types/core/float.rb +199 -0
- data/lib/types/core/gem.rb +19 -0
- data/lib/types/core/hash.rb +72 -0
- data/lib/types/core/integer.rb +194 -0
- data/lib/types/core/io.rb +101 -0
- data/lib/types/core/kernel.rb +89 -0
- data/lib/types/core/marshal.rb +3 -0
- data/lib/types/core/matchdata.rb +24 -0
- data/lib/types/core/math.rb +50 -0
- data/lib/types/core/module.rb +81 -0
- data/lib/types/core/nil.rb +11 -0
- data/lib/types/core/numeric.rb +56 -0
- data/lib/types/core/object.rb +73 -0
- data/lib/types/core/pathname.rb +104 -0
- data/lib/types/core/proc.rb +12 -0
- data/lib/types/core/process.rb +110 -0
- data/lib/types/core/random.rb +13 -0
- data/lib/types/core/range.rb +37 -0
- data/lib/types/core/rational.rb +207 -0
- data/lib/types/core/regexp.rb +28 -0
- data/lib/types/core/set.rb +56 -0
- data/lib/types/core/string.rb +140 -0
- data/lib/types/core/strscan.rb +6 -0
- data/lib/types/core/symbol.rb +27 -0
- data/lib/types/core/time.rb +66 -0
- data/lib/types/core/uri.rb +18 -0
- data/lib/types/core/yaml.rb +3 -0
- data/lib/types/devise.rb +1 -0
- data/lib/types/devise/controller_helpers.rb +3 -0
- data/lib/types/devise/parameter_sanitizer.rb +2 -0
- data/lib/types/pundit.rb +2 -0
- data/lib/types/rails/_helpers.rb +50 -0
- data/lib/types/rails/abstract_controller/translation.rb +2 -0
- data/lib/types/rails/action_controller/base.rb +3 -0
- data/lib/types/rails/action_controller/instrumentation.rb +6 -0
- data/lib/types/rails/action_controller/metal.rb +3 -0
- data/lib/types/rails/action_controller/mime_responds.rb +13 -0
- data/lib/types/rails/action_controller/parameters.rb +3 -0
- data/lib/types/{rails-5.x → rails}/action_controller/strong_parameters.rb +4 -8
- data/lib/types/rails/action_dispatch/flashhash.rb +8 -0
- data/lib/types/rails/action_dispatch/routing.rb +10 -0
- data/lib/types/rails/action_mailer/base.rb +2 -0
- data/lib/types/rails/action_mailer/message_delivery.rb +2 -0
- data/lib/types/rails/action_view/helpers_sanitizehelper.rb +2 -0
- data/lib/types/rails/action_view/helpers_urlhelper.rb +5 -0
- data/lib/types/rails/active_model/errors.rb +14 -0
- data/lib/types/rails/active_model/validations.rb +2 -0
- data/lib/types/rails/active_record/associations.rb +208 -0
- data/lib/types/rails/active_record/base.rb +2 -0
- data/lib/types/rails/active_record/core.rb +2 -0
- data/lib/types/rails/active_record/finder_methods.rb +2 -0
- data/lib/types/rails/active_record/model_schema.rb +37 -0
- data/lib/types/rails/active_record/relation.rb +11 -0
- data/lib/types/rails/active_record/schema_types.rb +51 -0
- data/lib/types/rails/active_record/validations.rb +2 -0
- data/lib/types/rails/active_support/base.rb +2 -0
- data/lib/types/rails/active_support/logger.rb +3 -0
- data/lib/types/rails/active_support/tagged_logging.rb +2 -0
- data/lib/types/rails/active_support/time_with_zone.rb +13 -0
- data/lib/types/rails/active_support/time_zone.rb +2 -0
- data/lib/types/rails/fixnum.rb +2 -0
- data/lib/types/rails/integer.rb +2 -0
- data/lib/types/rails/rack/request.rb +2 -0
- data/lib/types/rails/string.rb +3 -0
- data/lib/types/rails/time.rb +1 -0
- data/rdl.gemspec +2 -2
- data/test/disabled_test_rdoc.rb +8 -8
- data/test/test_alias.rb +1 -0
- data/test/test_dsl.rb +4 -4
- data/test/test_generic.rb +45 -38
- data/test/test_intersection.rb +10 -10
- data/test/test_le.rb +103 -102
- data/test/test_member.rb +33 -33
- data/test/test_parser.rb +101 -96
- data/test/test_query.rb +84 -84
- data/test/test_rdl.rb +87 -52
- data/test/test_rdl_type.rb +26 -9
- data/test/test_type_contract.rb +32 -31
- data/test/test_typecheck.rb +802 -436
- data/test/test_types.rb +39 -39
- data/test/test_wrap.rb +3 -2
- metadata +91 -120
- data/extras/type_tests/%.rb +0 -171
- data/extras/type_tests/&.rb +0 -159
- data/extras/type_tests/**.rb +0 -222
- data/extras/type_tests/*.rb +0 -177
- data/extras/type_tests/+.rb +0 -170
- data/extras/type_tests/-.rb +0 -171
- data/extras/type_tests/1scomp.rb +0 -157
- data/extras/type_tests/<.rb +0 -170
- data/extras/type_tests/<<.rb +0 -159
- data/extras/type_tests/>>.rb +0 -159
- data/extras/type_tests/[].rb +0 -163
- data/extras/type_tests/^.rb +0 -159
- data/extras/type_tests/abs.rb +0 -155
- data/extras/type_tests/abs2.rb +0 -164
- data/extras/type_tests/angle.rb +0 -157
- data/extras/type_tests/arg.rb +0 -157
- data/extras/type_tests/bit_length.rb +0 -157
- data/extras/type_tests/ceil.rb +0 -157
- data/extras/type_tests/ceilRational.rb +0 -160
- data/extras/type_tests/conj.rb +0 -158
- data/extras/type_tests/defwhere.rb +0 -86
- data/extras/type_tests/denominator.rb +0 -157
- data/extras/type_tests/div.rb +0 -172
- data/extras/type_tests/divslash.rb +0 -179
- data/extras/type_tests/even?.rb +0 -157
- data/extras/type_tests/fdiv.rb +0 -244
- data/extras/type_tests/finite?.rb +0 -157
- data/extras/type_tests/floor.rb +0 -157
- data/extras/type_tests/floorRational.rb +0 -161
- data/extras/type_tests/hash.rb +0 -157
- data/extras/type_tests/imag.rb +0 -158
- data/extras/type_tests/infinite?.rb +0 -157
- data/extras/type_tests/modulo.rb +0 -171
- data/extras/type_tests/nan?.rb +0 -157
- data/extras/type_tests/neg.rb +0 -155
- data/extras/type_tests/next.rb +0 -157
- data/extras/type_tests/next_float.rb +0 -157
- data/extras/type_tests/numerator.rb +0 -157
- data/extras/type_tests/phase.rb +0 -157
- data/extras/type_tests/prev_float.rb +0 -157
- data/extras/type_tests/quo.rb +0 -179
- data/extras/type_tests/rationalize.rb +0 -157
- data/extras/type_tests/rationalizeArg.rb +0 -198
- data/extras/type_tests/real.rb +0 -157
- data/extras/type_tests/real?.rb +0 -157
- data/extras/type_tests/round.rb +0 -157
- data/extras/type_tests/roundArg.rb +0 -169
- data/extras/type_tests/size.rb +0 -157
- data/extras/type_tests/to_c.rb +0 -157
- data/extras/type_tests/to_f.rb +0 -155
- data/extras/type_tests/to_i.rb +0 -157
- data/extras/type_tests/to_r.rb +0 -157
- data/extras/type_tests/to_s.rb +0 -157
- data/extras/type_tests/truncate.rb +0 -157
- data/extras/type_tests/truncateArg.rb +0 -166
- data/extras/type_tests/type tests +0 -1
- data/extras/type_tests/zero?.rb +0 -155
- data/extras/type_tests/|.rb +0 -159
- data/lib/types/core-ruby-2.x/_aliases.rb +0 -15
- data/lib/types/core-ruby-2.x/abbrev.rb +0 -5
- data/lib/types/core-ruby-2.x/array.rb +0 -137
- data/lib/types/core-ruby-2.x/base64.rb +0 -10
- data/lib/types/core-ruby-2.x/basic_object.rb +0 -14
- data/lib/types/core-ruby-2.x/benchmark.rb +0 -11
- data/lib/types/core-ruby-2.x/bigdecimal.rb +0 -224
- data/lib/types/core-ruby-2.x/bigmath.rb +0 -12
- data/lib/types/core-ruby-2.x/bignum.rb +0 -214
- data/lib/types/core-ruby-2.x/class.rb +0 -17
- data/lib/types/core-ruby-2.x/complex.rb +0 -124
- data/lib/types/core-ruby-2.x/coverage.rb +0 -6
- data/lib/types/core-ruby-2.x/csv.rb +0 -5
- data/lib/types/core-ruby-2.x/date.rb +0 -6
- data/lib/types/core-ruby-2.x/dir.rb +0 -38
- data/lib/types/core-ruby-2.x/encoding.rb +0 -23
- data/lib/types/core-ruby-2.x/enumerable.rb +0 -98
- data/lib/types/core-ruby-2.x/enumerator.rb +0 -26
- data/lib/types/core-ruby-2.x/exception.rb +0 -17
- data/lib/types/core-ruby-2.x/file.rb +0 -126
- data/lib/types/core-ruby-2.x/fileutils.rb +0 -6
- data/lib/types/core-ruby-2.x/fixnum.rb +0 -213
- data/lib/types/core-ruby-2.x/float.rb +0 -199
- data/lib/types/core-ruby-2.x/gem.rb +0 -247
- data/lib/types/core-ruby-2.x/hash.rb +0 -72
- data/lib/types/core-ruby-2.x/integer.rb +0 -197
- data/lib/types/core-ruby-2.x/io.rb +0 -103
- data/lib/types/core-ruby-2.x/kernel.rb +0 -90
- data/lib/types/core-ruby-2.x/marshal.rb +0 -5
- data/lib/types/core-ruby-2.x/matchdata.rb +0 -26
- data/lib/types/core-ruby-2.x/math.rb +0 -53
- data/lib/types/core-ruby-2.x/module.rb +0 -83
- data/lib/types/core-ruby-2.x/nil.rb +0 -12
- data/lib/types/core-ruby-2.x/numeric.rb +0 -56
- data/lib/types/core-ruby-2.x/object.rb +0 -75
- data/lib/types/core-ruby-2.x/pathname.rb +0 -106
- data/lib/types/core-ruby-2.x/proc.rb +0 -16
- data/lib/types/core-ruby-2.x/process.rb +0 -127
- data/lib/types/core-ruby-2.x/random.rb +0 -17
- data/lib/types/core-ruby-2.x/range.rb +0 -39
- data/lib/types/core-ruby-2.x/rational.rb +0 -209
- data/lib/types/core-ruby-2.x/regexp.rb +0 -30
- data/lib/types/core-ruby-2.x/set.rb +0 -58
- data/lib/types/core-ruby-2.x/string.rb +0 -143
- data/lib/types/core-ruby-2.x/strscan.rb +0 -7
- data/lib/types/core-ruby-2.x/symbol.rb +0 -29
- data/lib/types/core-ruby-2.x/time.rb +0 -68
- data/lib/types/core-ruby-2.x/uri.rb +0 -20
- data/lib/types/core-ruby-2.x/yaml.rb +0 -5
- data/lib/types/rails-5.x/_helpers.rb +0 -52
- data/lib/types/rails-5.x/action_controller/mime_responds.rb +0 -11
- data/lib/types/rails-5.x/action_dispatch/routing.rb +0 -10
- data/lib/types/rails-5.x/active_model/errors.rb +0 -15
- data/lib/types/rails-5.x/active_model/validations.rb +0 -5
- data/lib/types/rails-5.x/active_record/associations.rb +0 -190
- data/lib/types/rails-5.x/active_record/core.rb +0 -3
- data/lib/types/rails-5.x/active_record/model_schema.rb +0 -39
- data/lib/types/rails-5.x/fixnum.rb +0 -3
|
@@ -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,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,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,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,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
|