Sha256: 97fb25ccca43469faa4207768e329577c728403cb5f55ffd469e3535aa6d3a04

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module DataModel
	# Provides fixtures for testing date types
	module Fixtures::Date
		include Fixtures
		extend self

		# @return [Date] a date that is used by the #earliest example
		def earliest_date
			return ::Date.today - 1
		end

		# @return [Date] a date that is used by the #latest example
		def latest_date
			return ::Date.today + 1
		end

		# @return [Hash{Symbol => untyped}] the variants used by each example
		def variants
			today = ::Date.today

			{
				date: today,
				string: [today.to_s, today],
				invalid: "invalid",
				early: earliest_date - 1,
				late: latest_date + 1,
				missing: nil
			}
		end

		# A simple date schema
		# @return [Example] the example
		def simple
			Example.new([:date], variants:)
		end

		# A date schema that is optional
		# @return [Example] the example
		def optional
			Example.new([:date, { optional: true }], variants:)
		end

		# A date schema that has a restriction on the earliest date
		# @return [Example] the example
		def earliest
			Example.new([:date, { earliest: earliest_date }], variants:)
		end

		# A date schema that has a restriction on the latest date
		# @return [Example] the example
		def latest
			Example.new([:date, { latest: latest_date }], variants:)
		end
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
data_model-0.6.1 lib/data_model/fixtures/date.rb
data_model-0.6.0 lib/data_model/fixtures/date.rb
data_model-0.5.0 lib/data_model/fixtures/date.rb