Module: Finitio::RelBasedType
- Included in:
- MultiRelationType, RelationType
- Defined in:
- lib/finitio/type/rel_based_type.rb,
lib/finitio/generation/rel_based_type.rb,
lib/finitio/json_schema/rel_based_type.rb
Instance Method Summary collapse
-
#dress(value, handler = DressHelper.new) ⇒ Object
Apply the corresponding TupleType’s ‘dress` to every element of `value` (any enumerable).
- #generate_data(generator, world = nil) ⇒ Object
- #include?(value) ⇒ Boolean
- #representator ⇒ Object
- #to_json_schema(*args, &bl) ⇒ Object
Instance Method Details
#dress(value, handler = DressHelper.new) ⇒ Object
Apply the corresponding TupleType’s ‘dress` to every element of `value` (any enumerable). Return a Set of transformed tuples. Fail if anything goes wrong transforming tuples or if duplicates are found.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/finitio/type/rel_based_type.rb', line 17 def dress(value, handler = DressHelper.new) handler.failed!(self, value) unless value.respond_to?(:each) # Up every tuple and keep results in a Set set = Set.new handler.iterate(value) do |tuple, index| tuple = tuple_type.dress(tuple, handler) handler.fail!("Duplicate tuple") if set.include?(tuple) set << tuple end # Return built tuples set end |
#generate_data(generator, world = nil) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/finitio/generation/rel_based_type.rb', line 4 def generate_data(generator, world = nil) coll = [] generator.collection_size.times do coll << generator.call(tuple_type, world) end coll.uniq end |
#include?(value) ⇒ Boolean
8 9 10 11 12 |
# File 'lib/finitio/type/rel_based_type.rb', line 8 def include?(value) value.is_a?(Set) && value.all?{|tuple| tuple_type.include?(tuple) } end |
#representator ⇒ Object
4 5 6 |
# File 'lib/finitio/type/rel_based_type.rb', line 4 def representator [tuple_type.representator] end |
#to_json_schema(*args, &bl) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/finitio/json_schema/rel_based_type.rb', line 4 def to_json_schema(*args, &bl) { type: "array", items: tuple_type.to_json_schema(*args, &bl), uniqueItems: true } end |