Class: Fixtures::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/data_model/fixtures/example.rb

Overview

A simple abstraction to handle test data

Instance Method Summary collapse

Constructor Details

#initialize(schema, variants:) ⇒ Schema

Returns the schema.

Parameters:

  • schema (Array)

    the schema

  • variants (Hash{Symbol => untyped})

    the variants used by each example



7
8
9
10
# File 'lib/data_model/fixtures/example.rb', line 7

def initialize(schema, variants:)
	@schema = schema
	@variants = variants
end

Instance Method Details

#[](type) ⇒ Array(Model, untyped)

Returns a tuple of [model, variant].

Parameters:

  • type (Symbol)

    the variant to use

Returns:

  • (Array(Model, untyped))

    a tuple of [model, variant]



19
20
21
22
23
24
25
26
27
# File 'lib/data_model/fixtures/example.rb', line 19

def [](type)
	if !@variants.key?(type)
		raise "#{type} is not a defined variant: #{@variants}"
	end

	result = @variants.fetch(type)

	return [model, result]
end

#modelModel

Returns the model.

Returns:



13
14
15
# File 'lib/data_model/fixtures/example.rb', line 13

def model
	DataModel.define(@schema)
end