Skip to content

Commit 32e9e63

Browse files
committed
add in schema for sections, so we can generate prompts dynamically and ensure we keep things consistent along the way.
1 parent d76f81f commit 32e9e63

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

Rakefile

+9-6
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ namespace :add do
6363
category_file = File.join(__dir__, '_data/sections.yml')
6464
categories = SafeYAML.load_file(category_file)
6565
new_section = {}
66-
%w[id title icon page].each do |tag|
67-
new_section[tag] = value_prompt(tag)
66+
tags = tags_from_schema('sections_schema.yml', 'category')
67+
tags['mapping'].each do |tag|
68+
data = prompt_tag(tag[0], tag[1])
69+
new_section[tag[0]] = data unless data.nil?
6870
end
6971
if valid_to_ins(categories, new_section, 'id')
7072
categories[categories.count] = new_section
@@ -94,7 +96,8 @@ namespace :add do
9496
listing = {}
9597
site = {}
9698
section_file = prompt_category
97-
tags_from_schema['mapping'].each do |index|
99+
tags = tags_from_schema('websites_schema.yml', 'site')
100+
tags['mapping'].each do |index|
98101
data = prompt_tag(index[0], index[1])
99102
site[index[0]] = data unless data.nil?
100103
end
@@ -189,10 +192,10 @@ namespace :add do
189192
end
190193
# rubocop:enable Semicolon
191194

192-
def tags_from_schema
193-
schema = YAML.load_file(File.join(__dir__, 'websites_schema.yml'))
195+
def tags_from_schema(schema_file, class_name)
196+
schema = YAML.load_file(File.join(__dir__, schema_file))
194197
Kwalify::Util.traverse_schema(schema) do |rule|
195-
return rule if rule['name'] == 'Website'
198+
return rule if rule['class'] == class_name
196199
end
197200
end
198201

sections_schema.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
type: seq
2+
sequence:
3+
- type: map
4+
class: category
5+
name: category
6+
mapping:
7+
"id":
8+
type: str
9+
desc: Name of Category
10+
required: yes
11+
ident: yes
12+
unique: yes
13+
"title":
14+
type: str
15+
required: yes
16+
"icon":
17+
type: str
18+
required: yes
19+
"page":
20+
type: str
21+
required: yes
22+
enum: [home, adult, donations]

websites_schema.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
type: map
2-
class: Section
2+
class: websites
33
mapping:
44
"websites":
55
type: seq
66
sequence:
77
- type: map
8-
class: Site
8+
class: site
99
name: Website
1010
mapping:
1111
"name":

0 commit comments

Comments
 (0)