Class: GovukContentSchemaTestHelpers::Examples
- Inherits:
-
Object
- Object
- GovukContentSchemaTestHelpers::Examples
- Defined in:
- lib/govuk-content-schema-test-helpers/examples.rb
Instance Method Summary collapse
- #check_example_file_exists!(path) ⇒ Object
- #get(format, example_name) ⇒ Object
- #get_all_for_format(schema_name) ⇒ Object
- #get_all_for_formats(schema_names) ⇒ Object
-
#initialize ⇒ Examples
constructor
A new instance of Examples.
Constructor Details
#initialize ⇒ Examples
Returns a new instance of Examples.
3 4 5 |
# File 'lib/govuk-content-schema-test-helpers/examples.rb', line 3 def initialize Util.check_govuk_content_schemas_path! end |
Instance Method Details
#check_example_file_exists!(path) ⇒ Object
26 27 28 29 30 |
# File 'lib/govuk-content-schema-test-helpers/examples.rb', line 26 def check_example_file_exists!(path) if !File.exists?(path) raise ImproperlyConfiguredError, "Example file not found: #{path}." end end |
#get(format, example_name) ⇒ Object
7 8 9 10 11 |
# File 'lib/govuk-content-schema-test-helpers/examples.rb', line 7 def get(format, example_name) path = example_path(format, example_name) check_example_file_exists!(path) File.read(path) end |
#get_all_for_format(schema_name) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/govuk-content-schema-test-helpers/examples.rb', line 13 def get_all_for_format(schema_name) glob_path = example_path(schema_name, '*') Dir.glob(glob_path).map do |path| File.read(path) end end |
#get_all_for_formats(schema_names) ⇒ Object
20 21 22 23 24 |
# File 'lib/govuk-content-schema-test-helpers/examples.rb', line 20 def get_all_for_formats(schema_names) schema_names.inject([]) do |memo, schema_name| memo + get_all_for_format(schema_name) end end |