finitio 0.11.3 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +42 -19
  3. data/Gemfile.lock +18 -18
  4. data/finitio.gemspec +3 -3
  5. data/lib/finitio/generation/proxy_type.rb +11 -0
  6. data/lib/finitio/generation.rb +1 -0
  7. data/lib/finitio/json_schema/builtin_type.rb +0 -2
  8. data/lib/finitio/json_schema/hash_based_type.rb +1 -1
  9. data/lib/finitio/json_schema/proxy_type.rb +4 -5
  10. data/lib/finitio/stdlib/finitio/data.fio +2 -2
  11. data/lib/finitio/support/compilation.rb +0 -4
  12. data/lib/finitio/support/proxy_resolver.rb +52 -0
  13. data/lib/finitio/support.rb +1 -0
  14. data/lib/finitio/syntax.rb +4 -4
  15. data/lib/finitio/system.rb +5 -16
  16. data/lib/finitio/type/ad_type.rb +1 -1
  17. data/lib/finitio/type/builtin_type.rb +4 -4
  18. data/lib/finitio/type/high_order_type.rb +3 -1
  19. data/lib/finitio/type/proxy_type.rb +19 -1
  20. data/lib/finitio/type/struct_type.rb +2 -2
  21. data/lib/finitio/type/sub_type.rb +2 -2
  22. data/lib/finitio/type/tuple_type.rb +3 -3
  23. data/lib/finitio/type/union_type.rb +2 -2
  24. data/lib/finitio/type.rb +4 -2
  25. data/lib/finitio/version.rb +2 -2
  26. data/spec/finitio/test_ast.rb +2 -2
  27. data/spec/finitio/test_parse.rb +1 -1
  28. data/spec/finitio/test_system.rb +1 -1
  29. data/spec/inference/test_inference.rb +1 -1
  30. data/spec/json_schema/test_builtin_type.rb +4 -6
  31. data/spec/json_schema/test_recursive_type.rb +2 -12
  32. data/spec/regression/test_dress_on_recursive_type.rb +53 -0
  33. data/spec/regression/test_name_of_generic_types.rb +18 -0
  34. data/spec/syntax/test_compile.rb +19 -1
  35. data/spec/type_factory/factory/test_sub_type.rb +3 -3
  36. metadata +175 -170
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: acf74d5293b979c7c03d55dc9cbea273b9f85d6c
4
- data.tar.gz: 14e18b10f4668fc996354ec2ceb6627eb56dffbc
2
+ SHA256:
3
+ metadata.gz: 92c67dd32e89dd6c4597b4a8456572bb1a5b3de07bdf58e88bcb9dc3f0874462
4
+ data.tar.gz: 4ecd7898e477113040613415f9bc2cc8f23bc3605d0f71a3ccaefbbe1eaf31ff
5
5
  SHA512:
6
- metadata.gz: ba3a092904c8ac102361ef17b2fc0f49d8f6ed209d2a3ffe0ec852f3c3b52772716762bf65d3604831a631f2ecc8782cdaa120b7768608849ec72bdbc164f8d2
7
- data.tar.gz: a33d566ed9e25caed8b90d7228583056152ee1fb0c50533fad4008ab72d318fd3d51430f1f50146f42c77104f6fad40c86591200e168cce14de05d46995e228d
6
+ metadata.gz: eb3042b639a82d469bb760807e6c94e1f70c39a3249420d30e339d5f004048e8abe6026de3b3b834e3703f88b3dd10a6d2937abdba5a183444af13609cc150b5
7
+ data.tar.gz: f44c30f37848ad1e0b8344487cc0f0353ad694ce31c535ff6dd4ae02e903bebc92d11b29ac78ae0aa7d21f7bce6ba3fbd7ecdceb2cb6d14aa4bd3f9d6fb5164a
data/CHANGELOG.md CHANGED
@@ -1,24 +1,47 @@
1
- # 0.11.3 - 2023/01/06
1
+ ## 0.12.0 - 2023/05/23
2
+
3
+ * Remove support for ruby < 2.6
4
+
5
+ * Remove support for .Fixnum and .Bignum, .Integer is now used
6
+ everywhere. To ease the transition, Fixum and Bignum still exist
7
+ in the finitio/data stdlib schema, but will be removed in 0.13.x
8
+
9
+ ## 0.11.4 - 2023/01/06
10
+
11
+ * The proxy resolution is fixed and clarified. When compiling
12
+ a system, all proxies are actually replaced by their actual
13
+ Type instance. Only recursive types still keep ProxyType
14
+ instances (as sentinels) ; they are bound to their target
15
+ type and delete dress and include? to them.
16
+
17
+ Given that ProxyType is a sentinel on recursive types, calls
18
+ to generate_data and to_json_schema are not delegated to the
19
+ target type, to avoid infinite recursions.
20
+
21
+ * Generated names of instantiated high order types are better
22
+ (e.g. Collection<String>).
23
+
24
+ ## 0.11.3 - 2023/01/06
2
25
 
3
26
  * Fix json_schema generation on unresolved ProxyTypes. We use
4
27
  "object" by default, waiting for a better support for recursive
5
28
  types.
6
29
 
7
- # 0.11.2 - 2023/01/06
30
+ ## 0.11.2 - 2023/01/06
8
31
 
9
32
  * Fix json_schema generation on builtin_type NilClass. "null"
10
33
  is not a valid value, we now use "string" instead.
11
34
 
12
- # 0.11.1 - 2021/12/09
35
+ ## 0.11.1 - 2021/12/09
13
36
 
14
37
  * Fix github actions and extend test grid.
15
38
 
16
- # 0.11.0 - 2021/12/09
39
+ ## 0.11.0 - 2021/12/09
17
40
 
18
41
  * Fix json schema generation of Boolean and union types with a |Nil
19
42
  * Add support for dashses in attribute names (tuple & relation types).
20
43
 
21
- # 0.10.0 - 2021/01/11
44
+ ## 0.10.0 - 2021/01/11
22
45
 
23
46
  * Upgrade all dependencies.
24
47
 
@@ -26,18 +49,18 @@
26
49
 
27
50
  * Fix code and build under Ruby 3.0.
28
51
 
29
- # 0.9.1 - 2020/12/24
52
+ ## 0.9.1 - 2020/12/24
30
53
 
31
54
  * Fixes a bug where proxy types are not properly resolved when used
32
55
  in a heading extra, e.g. `{ ...: Proxy }`
33
56
 
34
- # 0.9.0 - 2020/12/16
57
+ ## 0.9.0 - 2020/12/16
35
58
 
36
59
  * Add Type#to_json_schema that converts Finitio types to JSON schema
37
60
  representations. This first implementation skips all constraints on sub types,
38
61
  though. You need to explicitly require 'finitio/json_schema' to use it.
39
62
 
40
- # 0.8.0 - 2019/10/21
63
+ ## 0.8.0 - 2019/10/21
41
64
 
42
65
  * Add `Type#unconstrained` that returns a super type with all user specific
43
66
  constraints removed on sub types, recursively on all non scalar types.
@@ -47,7 +70,7 @@
47
70
  * Add support for random data generation through `Finitio::Generation`.
48
71
  Please `require 'finitio/generation'` to use it.
49
72
 
50
- # 0.7.0 / 2019-02-28
73
+ ## 0.7.0 / 2019-02-28
51
74
 
52
75
  * Implement (basic) @import feature, working with relative paths
53
76
  and a standard library. The standard library systems are memoized
@@ -60,28 +83,28 @@
60
83
  * WARN: Finitio::DEFAULT_SYSTEM is deprecated. Use @import
61
84
  finitio/data instead.
62
85
 
63
- # 0.6.1 / 2018-03-23
86
+ ## 0.6.1 / 2018-03-23
64
87
 
65
88
  * Fix support for typed extra attributes, a KeyError was raised when
66
89
  keys were Symbols and not Strings.
67
90
 
68
- # 0.6.0 / 2018-02-17
91
+ ## 0.6.0 / 2018-02-17
69
92
 
70
93
  * Add support for typed extra attributes, e.g. { ...: Integer }
71
94
 
72
- # 0.5.2 / 2017-01-08
95
+ ## 0.5.2 / 2017-01-08
73
96
 
74
97
  * Disable memoization in parser because it leads to terrible performance
75
98
  issues on some schemas.
76
99
  * Avoid alternatives on high-level rules (Union, SubType) to prevent many
77
100
  fallbacks that kill performance without memoization enabled.
78
101
 
79
- # 0.5.1 / 2015-09-22
102
+ ## 0.5.1 / 2015-09-22
80
103
 
81
104
  * Enabled memoization in parser to avoid very long parsing time on complex
82
105
  schemas.
83
106
 
84
- # 0.5.0 / 2015-09-18
107
+ ## 0.5.0 / 2015-09-18
85
108
 
86
109
  * Breaking changes on public API
87
110
 
@@ -147,29 +170,29 @@
147
170
  * Make Finitio compatible with both Citrus 2.4.x and Citrus 3.x
148
171
  * Fixed parsing of constraint expressions having inner parentheses
149
172
 
150
- # 0.4.1 / 2014-03-20
173
+ ## 0.4.1 / 2014-03-20
151
174
 
152
175
  * Fixed access to the default system that lead to 'Unknown system
153
176
  Finitio/default (Finitio::Error)'
154
177
 
155
- # 0.4.0 / 2014-03-20
178
+ ## 0.4.0 / 2014-03-20
156
179
 
157
180
  * Finitio(-rb) is born from the sources of Q(rb) 0.3.0
158
181
  * Finitio.parse now recognizes Path-like objects (responding to :to_path),
159
182
  allowing to parse files directly (through Pathname, Path, etc.).
160
183
 
161
- # 0.3.0 / 2014-03-09
184
+ ## 0.3.0 / 2014-03-09
162
185
 
163
186
  * Added AnyType abstraction, aka '.'
164
187
  * Added support for external contracts in ADTs
165
188
  * Added support for extracting an Abstract Syntax Tree from parsing result
166
189
  * Allows camelCasing in constraint names
167
190
 
168
- # 0.2.0 / 2014-03-04
191
+ ## 0.2.0 / 2014-03-04
169
192
 
170
193
  * Fix dependencies in gemspec (judofyr)
171
194
 
172
- # 0.1.0 / 2014-03-03
195
+ ## 0.1.0 / 2014-03-03
173
196
 
174
197
  * Enhancements
175
198
 
data/Gemfile.lock CHANGED
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- finitio (0.11.3)
4
+ finitio (0.12.0)
5
5
  citrus (>= 3.0, < 4.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.2.8.1)
10
+ activesupport (7.0.4.3)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
15
  awesome_print (1.9.2)
16
16
  builder (3.2.4)
17
17
  citrus (3.0.2)
18
- concurrent-ruby (1.1.10)
18
+ concurrent-ruby (1.2.2)
19
19
  coveralls (0.8.23)
20
20
  json (>= 1.8, < 3)
21
21
  simplecov (~> 0.16.1)
@@ -54,16 +54,16 @@ GEM
54
54
  cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
55
55
  cucumber-messages (~> 12.2, >= 12.2.0)
56
56
  diff-lcs (1.3)
57
- docile (1.3.5)
57
+ docile (1.4.0)
58
58
  ffi (1.15.5)
59
- i18n (1.12.0)
59
+ i18n (1.13.0)
60
60
  concurrent-ruby (~> 1.0)
61
61
  json (2.6.3)
62
62
  middleware (0.1.0)
63
- minitest (5.15.0)
63
+ minitest (5.18.0)
64
64
  multi_json (1.15.0)
65
65
  multi_test (0.1.2)
66
- path (2.0.1)
66
+ path (2.1.0)
67
67
  protobuf-cucumber (3.10.8)
68
68
  activesupport (>= 3.2)
69
69
  middleware
@@ -74,12 +74,12 @@ GEM
74
74
  rspec-core (~> 3.12.0)
75
75
  rspec-expectations (~> 3.12.0)
76
76
  rspec-mocks (~> 3.12.0)
77
- rspec-core (3.12.0)
77
+ rspec-core (3.12.2)
78
78
  rspec-support (~> 3.12.0)
79
- rspec-expectations (3.12.1)
79
+ rspec-expectations (3.12.3)
80
80
  diff-lcs (>= 1.2.0, < 2.0)
81
81
  rspec-support (~> 3.12.0)
82
- rspec-mocks (3.12.1)
82
+ rspec-mocks (3.12.5)
83
83
  diff-lcs (>= 1.2.0, < 2.0)
84
84
  rspec-support (~> 3.12.0)
85
85
  rspec-support (3.12.0)
@@ -89,16 +89,16 @@ GEM
89
89
  simplecov-html (~> 0.10.0)
90
90
  simplecov-html (0.10.2)
91
91
  sync (0.5.0)
92
- sys-uname (1.2.2)
92
+ sys-uname (1.2.3)
93
93
  ffi (~> 1.1)
94
94
  term-ansicolor (1.7.1)
95
95
  tins (~> 1.0)
96
- thor (1.2.1)
96
+ thor (1.2.2)
97
97
  thread_safe (0.3.6)
98
98
  tins (1.32.1)
99
99
  sync
100
- tzinfo (1.2.10)
101
- thread_safe (~> 0.1)
100
+ tzinfo (2.0.6)
101
+ concurrent-ruby (~> 1.0)
102
102
 
103
103
  PLATFORMS
104
104
  x86_64-linux
@@ -109,7 +109,7 @@ DEPENDENCIES
109
109
  cucumber (~> 4.1)
110
110
  finitio!
111
111
  multi_json (~> 1.15)
112
- path (>= 2.0, < 3.0)
112
+ path (>= 2.1, < 3.0)
113
113
  rake (~> 13.0)
114
114
  rspec (~> 3.0)
115
115
 
data/finitio.gemspec CHANGED
@@ -19,13 +19,13 @@ Gem::Specification.new do |s|
19
19
  s.test_files = Dir["test/**/*"] + Dir["spec/**/*"]
20
20
  s.bindir = "bin"
21
21
  s.executables = (Dir["bin/*"]).collect{|f| File.basename(f)}
22
-
22
+
23
23
  s.add_dependency("citrus", ">= 3.0", "< 4.0")
24
-
24
+
25
25
  s.add_development_dependency("rake", "~> 13.0")
26
26
  s.add_development_dependency("rspec", "~> 3.0")
27
27
  s.add_development_dependency("cucumber", "~> 4.1")
28
- s.add_development_dependency("path", ">= 2.0", "< 3.0")
28
+ s.add_development_dependency("path", ">= 2.1", "< 3.0")
29
29
  s.add_development_dependency("awesome_print", "~> 1.8")
30
30
  s.add_development_dependency("coveralls", "~> 0.8")
31
31
  s.add_development_dependency("multi_json", "~> 1.15")
@@ -0,0 +1,11 @@
1
+ module Finitio
2
+ class ProxyType
3
+
4
+ def generate_data(*args, &bl)
5
+ # Proxy type is supposed to be used only on recursive types
6
+ # so we can't go further to avoid a infinite recursion
7
+ {}
8
+ end
9
+
10
+ end # class ProxyType
11
+ end # module Finitio
@@ -104,3 +104,4 @@ require_relative 'generation/union_type'
104
104
  require_relative 'generation/alias_type'
105
105
  require_relative 'generation/sub_type'
106
106
  require_relative 'generation/ad_type'
107
+ require_relative 'generation/proxy_type'
@@ -5,8 +5,6 @@ module Finitio
5
5
  NilClass => "string", # jsonapi does not support null
6
6
  String => "string",
7
7
  Integer => "integer",
8
- Fixnum => "integer",
9
- Bignum => "integer",
10
8
  Float => "number",
11
9
  Numeric => "number",
12
10
  TrueClass => "boolean",
@@ -7,7 +7,7 @@ module Finitio
7
7
  }
8
8
  unless heading.empty?
9
9
  base[:properties] = heading.inject({}){|ps,a|
10
- ps.merge(a.name => a.type.to_json_schema(*args, &bl))
10
+ ps.merge(a.name => a.type.to_json_schema(*args, &bl))
11
11
  }
12
12
  end
13
13
  unless (reqs = heading.select{|a| a.required? }).empty?
@@ -2,11 +2,10 @@ module Finitio
2
2
  class ProxyType
3
3
 
4
4
  def to_json_schema(*args, &bl)
5
- if @target
6
- @target.to_json_schema(*args, &bl)
7
- else
8
- "object"
9
- end
5
+ # ProxyType is supposed to be used only for recursive types.
6
+ # We don't have support for references yet, so let just
7
+ # generate an object here in the mean time.
8
+ { type: "object" }
10
9
  end
11
10
 
12
11
  end # module ProxyType
@@ -11,8 +11,8 @@ Boolean = .TrueClass|.FalseClass
11
11
 
12
12
  # Numbers
13
13
  Numeric = .Numeric
14
- Fixnum = .Fixnum
15
- Bignum = .Bignum
14
+ Fixnum = .Integer
15
+ Bignum = .Integer
16
16
  Integer = .Integer
17
17
  Float = .Float
18
18
  Real = .Float
@@ -48,10 +48,6 @@ module Finitio
48
48
  Pathname.new(file)
49
49
  end
50
50
 
51
- def resolve_proxies
52
- system.resolve_proxies
53
- end
54
-
55
51
  # Delegation to Factory
56
52
 
57
53
  TypeFactory::DSL_METHODS.each do |dsl_method|
@@ -0,0 +1,52 @@
1
+ module Finitio
2
+ # Part of the compilation schema, this proxy resolver replaces
3
+ # proxies by their real Type instance.
4
+ #
5
+ # Given that Finitio can support recursive types, we do this in
6
+ # two passes:
7
+ # 1. Replace proxy types by rewrite (see Type#resolve_proxies)
8
+ # in a depth first search.
9
+ # 2. If a loop is found, recreate a late ProxyType, that is then
10
+ # bound later by mutation.
11
+ #
12
+ # So ProxyType may still be present in the type chain, but will
13
+ # only correspond to recursive types.
14
+ class ProxyResolver
15
+ def resolve!(system)
16
+ @system = system
17
+ @built = {}
18
+ @building = {}
19
+ @late_proxies = []
20
+ system.types.each_key do |name|
21
+ fetch(name)
22
+ end
23
+ @late_proxies.each do |proxy|
24
+ proxy.bind!(self)
25
+ end
26
+ system.dup(@built)
27
+ end
28
+
29
+ def fetch(name, &bl)
30
+ @built[name] || build_it(name) || import_it(name, &bl)
31
+ end
32
+
33
+ def build_it(name)
34
+ if under_build = @building[name]
35
+ proxy = ProxyType.new(name)
36
+ @late_proxies << proxy
37
+ proxy
38
+ else
39
+ return nil unless type = @system.fetch(name, false){ nil }
40
+
41
+ @building[name] = type
42
+ @built[name] = type.resolve_proxies(self)
43
+ @building[name] = nil
44
+ @built[name]
45
+ end
46
+ end
47
+
48
+ def import_it(name, &bl)
49
+ @system.fetch_on_imports(name, &bl)
50
+ end
51
+ end # class ProxyResolver
52
+ end # module Finitio
@@ -24,4 +24,5 @@ require_relative 'support/heading'
24
24
  require_relative 'support/dress_helper'
25
25
  require_relative 'support/type_factory'
26
26
  require_relative 'support/fetch_scope'
27
+ require_relative 'support/proxy_resolver'
27
28
  require_relative 'support/compilation'
@@ -21,18 +21,18 @@ module Finitio
21
21
  end
22
22
 
23
23
  def self.ast(source)
24
- parse(source, root: "system").to_ast
24
+ parse(source, root: 'system').to_ast
25
25
  end
26
26
 
27
27
  def self.compile(source, cpl = nil)
28
28
  cpl = Compilation.coerce(cpl, source)
29
- parse(source, root: "system").compile(cpl)
30
- cpl.resolve_proxies
29
+ parse(source, root: 'system').compile(cpl)
30
+ ProxyResolver.new.resolve!(cpl.system)
31
31
  end
32
32
 
33
33
  def self.compile_type(source, cpl = nil)
34
34
  cpl = Compilation.coerce(cpl, source)
35
- parse(source, root: "type").compile(cpl)
35
+ parse(source, root: 'type').compile(cpl)
36
36
  end
37
37
 
38
38
  end # module Syntax
@@ -50,24 +50,23 @@ module Finitio
50
50
  def fetch(name, with_imports = true, &bl)
51
51
  if with_imports
52
52
  @types.fetch(name) do
53
- _fetch(name, @imports, &bl)
53
+ fetch_on_imports(name, &bl)
54
54
  end
55
55
  else
56
56
  @types.fetch(name, &bl)
57
57
  end
58
58
  end
59
59
 
60
- def _fetch(name, imports, &bl)
60
+ def fetch_on_imports(name, imports = @imports, &bl)
61
61
  if imports.empty?
62
62
  raise KeyError, %Q{key not found: "#{name}"} unless bl
63
63
  bl.call(name)
64
64
  else
65
65
  imports.first.fetch(name, false) do
66
- _fetch(name, imports[1..-1], &bl)
66
+ fetch_on_imports(name, imports[1..-1], &bl)
67
67
  end
68
68
  end
69
69
  end
70
- private :_fetch
71
70
 
72
71
  def factory
73
72
  @factory ||= TypeFactory.new
@@ -89,22 +88,12 @@ module Finitio
89
88
  Syntax.compile(source, self.dup)
90
89
  end
91
90
 
92
- def resolve_proxies(recurse = true)
93
- rebuilt = {}
94
- scope = FetchScope.new(self, rebuilt)
95
- types.each_with_object(rebuilt) do |(name,type),memo|
96
- rebuilt[name] = type.resolve_proxies(scope)
97
- end
98
- resolved = System.new(rebuilt, imports)
99
- recurse ? resolved.resolve_proxies(false) : resolved
100
- end
101
-
102
91
  def inspect
103
92
  @types.each_pair.map{|k,v| "#{k} = #{v}" }.join("\n")
104
93
  end
105
94
 
106
- def dup
107
- System.new(@types.dup, @imports.dup)
95
+ def dup(types = @types.dup, imports = @imports.dup)
96
+ System.new(types, imports)
108
97
  end
109
98
 
110
99
  def check_and_warn(logger = nil)
@@ -30,7 +30,7 @@ module Finitio
30
30
  # rgb_infotype = TupleType.new(...)
31
31
  #
32
32
  # # The RGB contract converter, an object that responds to `call` to
33
- # # convert from a valid Hash[r: Fixnum, ...] to a ColorImpl instance.
33
+ # # convert from a valid Hash[r: Integer, ...] to a ColorImpl instance.
34
34
  # rgb_contract = ...
35
35
  #
36
36
  # AdType.new(ColorImpl, rgb: [rgb_infotype, rgb_contract], hex: ...)
@@ -3,21 +3,21 @@ module Finitio
3
3
  # A BuiltinType generator allows capuring an information type to a type of
4
4
  # the host language, here a Ruby class. For instance,
5
5
  #
6
- # Int := BuiltinType(ruby.Fixnum)
6
+ # Int := BuiltinType(ruby.Integer)
7
7
  #
8
8
  # The set of values captured by the information type is the same set of
9
9
  # values that can be represented by the host type. In the example, `Int`
10
- # captures the same set of numbers as ruby's Fixnum.
10
+ # captures the same set of numbers as ruby's Integer.
11
11
  #
12
12
  # The ruby class is used as concrete representation of the information type.
13
13
  # In the example:
14
14
  #
15
- # R(Int) = Fixnum
15
+ # R(Int) = Integer
16
16
  #
17
17
  # Accordingly, the `dress` transformation function has the following signature:
18
18
  #
19
19
  # dress :: Alpha -> Int throws TypeError
20
- # dress :: Object -> Fixnum throws TypeError
20
+ # dress :: Object -> Integer throws TypeError
21
21
  #
22
22
  class BuiltinType < Type
23
23
 
@@ -28,7 +28,9 @@ module Finitio
28
28
 
29
29
  def instantiate(compilation, sub_types)
30
30
  overrides = Hash[vars.zip(sub_types)]
31
- defn.resolve_proxies(compilation.with_scope(overrides))
31
+ defn.resolve_proxies(compilation.with_scope(overrides)).dup.tap{|x|
32
+ x.send(:name=, "#{name}<#{overrides.values.join(',')}>", true)
33
+ }
32
34
  end
33
35
 
34
36
  def unconstrained
@@ -15,8 +15,26 @@ module Finitio
15
15
  "_#{target_name}_"
16
16
  end
17
17
 
18
+ def include?(*args, &bl)
19
+ raise Error, "Proxy not resolved: #{target_name}" unless @target
20
+
21
+ @target.include?(*args, &bl)
22
+ end
23
+
24
+ def dress(*args, &bl)
25
+ raise Error, "Proxy not resolved: #{target_name}" unless @target
26
+
27
+ @target.dress(*args, &bl)
28
+ end
29
+
30
+ def bind!(system)
31
+ @target = system.fetch(target_name) {
32
+ raise Error, "No such type `#{target_name}` in #{system}"
33
+ }
34
+ end
35
+
18
36
  def resolve_proxies(system)
19
- system.fetch(target_name){
37
+ system.fetch(target_name) {
20
38
  raise Error, "No such type `#{target_name}` in #{system}"
21
39
  }
22
40
  end
@@ -8,7 +8,7 @@ module Finitio
8
8
  #
9
9
  # This class allows capturing those information types, as in:
10
10
  #
11
- # Length = BuiltinType.new(Fixnum)
11
+ # Length = BuiltinType.new(Integer)
12
12
  # Angle = BuiltinType.new(Float)
13
13
  # Point = StructType.new([Length, Angle])
14
14
  #
@@ -16,7 +16,7 @@ module Finitio
16
16
  # values map to the concrete representations of each component type:
17
17
  #
18
18
  # R(Point) = Array[R(Length) ^ R(Angle)]
19
- # = Array[Fixnum ^ Float]
19
+ # = Array[Integer ^ Float]
20
20
  # = Array[Numeric]
21
21
  #
22
22
  # where `^` denotes the `least common super type` operator on ruby classes.
@@ -18,12 +18,12 @@ module Finitio
18
18
  # The concrete representation of the super type is kept as representation
19
19
  # of the sub type. In other words:
20
20
  #
21
- # R(Byte) = R(Int) = Fixnum
21
+ # R(Byte) = R(Int) = Integer
22
22
  #
23
23
  # Accordingly, the `dress` transformation function has the following signature:
24
24
  #
25
25
  # dress :: Alpha -> Byte throws TypeError
26
- # dress :: Object -> Fixnum throws TypeError
26
+ # dress :: Object -> Integer throws TypeError
27
27
  #
28
28
  class SubType < Type
29
29
 
@@ -7,7 +7,7 @@ module Finitio
7
7
  #
8
8
  # This class allows capturing those information types, as in:
9
9
  #
10
- # Length = BuiltinType.new(Fixnum)
10
+ # Length = BuiltinType.new(Integer)
11
11
  # Angle = BuiltinType.new(Float)
12
12
  # Point = TupleType.new(Heading.new([
13
13
  # Attribute.new(:r, Length),
@@ -19,7 +19,7 @@ module Finitio
19
19
  # type:
20
20
  #
21
21
  # R(Point) = Hash[r: R(Length), theta: R(Angle)]
22
- # = Hash[r: Fixnum, theta: Float]
22
+ # = Hash[r: Integer, theta: Float]
23
23
  #
24
24
  # Accordingly, the `dress` transformation function has the signature below.
25
25
  # It expects it's Alpha/Object argument to be a Hash with all and only the
@@ -27,7 +27,7 @@ module Finitio
27
27
  # applies on every attribute value according to their respective type.
28
28
  #
29
29
  # dress :: Alpha -> Point throws TypeError
30
- # dress :: Object -> Hash[r: Fixnum, theta: Float] throws TypeError
30
+ # dress :: Object -> Hash[r: Integer, theta: Float] throws TypeError
31
31
  #
32
32
  class TupleType < Type
33
33
  include HeadingBasedType
@@ -8,7 +8,7 @@ module Finitio
8
8
  #
9
9
  # This class allows capturing such union types, as follows:
10
10
  #
11
- # Int = BuiltinType.new(Fixnum)
11
+ # Int = BuiltinType.new(Integer)
12
12
  # Real = BuiltinType.new(Float)
13
13
  # Numeric = UnionType.new([ Int, Real ])
14
14
  #
@@ -17,7 +17,7 @@ module Finitio
17
17
  # value ends the process and the value is simply returned. Accordingly,
18
18
  # the concrete representation will be
19
19
  #
20
- # R(Numeric) = R(Int) ^ R(Real) = Fixnum ^ Float = Numeric
20
+ # R(Numeric) = R(Int) ^ R(Real) = Integer ^ Float = Numeric
21
21
  #
22
22
  # where `^` denotes the `least common super type` operator on ruby classes.
23
23
  #
data/lib/finitio/type.rb CHANGED
@@ -32,8 +32,10 @@ module Finitio
32
32
  @name || default_name
33
33
  end
34
34
 
35
- def name=(n)
36
- raise Error, "Name already set to `#{@name}`" unless @name.nil?
35
+ def name=(n, force = false)
36
+ if !@name.nil? && !force
37
+ raise Error, "Name already set to `#{@name}` on #{self.class}"
38
+ end
37
39
  @name = n
38
40
  end
39
41