Class: Finitio::BuiltinType
- Defined in:
- lib/finitio/type/builtin_type.rb,
lib/finitio/generation/builtin_type.rb,
lib/finitio/json_schema/builtin_type.rb
Overview
A BuiltinType generator allows capuring an information type to a type of the host language, here a Ruby class. For instance,
Int := BuiltinType(ruby.Fixnum)
The set of values captured by the information type is the same set of values that can be represented by the host type. In the example, Int captures the same set of numbers as ruby’s Fixnum.
The ruby class is used as concrete representation of the information type. In the example:
R(Int) = Fixnum
Accordingly, the dress transformation function has the following signature:
dress :: Alpha -> Int throws TypeError
dress :: Object -> Fixnum throws TypeError
Constant Summary
Constants included from Metadata
Instance Attribute Summary collapse
-
#ruby_type ⇒ Object
(also: #representator)
readonly
Returns the value of attribute ruby_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #default_name ⇒ Object
-
#dress(value, handler = DressHelper.new) ⇒ Object
Check that
valueis a valid instance ofruby_typethrough ‘===` or raise an error. - #generate_data(generator, world = nil) ⇒ Object
- #hash ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize(ruby_type, name = nil, metadata = nil) ⇒ BuiltinType
constructor
A new instance of BuiltinType.
- #resolve_proxies(system) ⇒ Object
- #to_json_schema(*args, &bl) ⇒ Object
Methods inherited from Type
#anonymous?, #name, #name=, #named?, #suppremum, #to_s, #unconstrained
Methods included from Metadata
#metadata, #metadata=, #metadata?
Constructor Details
#initialize(ruby_type, name = nil, metadata = nil) ⇒ BuiltinType
Returns a new instance of BuiltinType.
24 25 26 27 |
# File 'lib/finitio/type/builtin_type.rb', line 24 def initialize(ruby_type, name = nil, = nil) super(name, ) @ruby_type = ruby_type end |
Instance Attribute Details
#ruby_type ⇒ Object (readonly) Also known as: representator
Returns the value of attribute ruby_type.
28 29 30 |
# File 'lib/finitio/type/builtin_type.rb', line 28 def ruby_type @ruby_type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/finitio/type/builtin_type.rb', line 47 def ==(other) super || (other.is_a?(BuiltinType) && other.ruby_type==ruby_type) end |
#default_name ⇒ Object
32 33 34 |
# File 'lib/finitio/type/builtin_type.rb', line 32 def default_name @ruby_type.name.to_s end |
#dress(value, handler = DressHelper.new) ⇒ Object
Check that value is a valid instance of ruby_type through ‘===` or raise an error.
42 43 44 45 |
# File 'lib/finitio/type/builtin_type.rb', line 42 def dress(value, handler = DressHelper.new) handler.failed!(self, value) unless ruby_type===value value end |
#generate_data(generator, world = nil) ⇒ Object
4 5 6 |
# File 'lib/finitio/generation/builtin_type.rb', line 4 def generate_data(generator, world = nil) generator.heuristic.call(ruby_type, generator, world) end |
#hash ⇒ Object
52 53 54 |
# File 'lib/finitio/type/builtin_type.rb', line 52 def hash self.class.hash ^ ruby_type.hash end |
#include?(value) ⇒ Boolean
36 37 38 |
# File 'lib/finitio/type/builtin_type.rb', line 36 def include?(value) ruby_type === value end |
#resolve_proxies(system) ⇒ Object
56 57 58 |
# File 'lib/finitio/type/builtin_type.rb', line 56 def resolve_proxies(system) self end |
#to_json_schema(*args, &bl) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/finitio/json_schema/builtin_type.rb', line 17 def to_json_schema(*args, &bl) mapped = JsonSchema::BUILTIN_MAPPING[ruby_type] if mapped { type: mapped } else raise JsonSchema::Error, "Unable to map #{ruby_type} to json-schema" end end |