Sha256: 8428491b6c7a7f53a0329b005830ad5812913b64c3e760398f93bdc458690bda

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module DataModel
	# Test data around time schemas
	module Fixtures::Time
		include Fixtures
		extend self

		# @return [Time] a time that is used by the #earliest example
		def earliest_time
			return ::Time.now - 1
		end

		# @return [Time] a time that is used by the #latest example
		def latest_time
			return ::Time.now + 1
		end

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

			{
				time: now,
				string: [now.strftime("%H:%M:%S.%6N"), now],
				invalid: "invalid",
				early: earliest_time - 1,
				late: latest_time + 1,
				missing: nil
			}
		end

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

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

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

		# A time schema that has a restriction on the latest time
		# @return [Example] the example
		def latest
			Example.new([:time, { latest: latest_time }], 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/time.rb
data_model-0.6.0 lib/data_model/fixtures/time.rb
data_model-0.5.0 lib/data_model/fixtures/time.rb