Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Struct in examples #538

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions guide/lib/setup/example_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,48 @@ module Setup
module ExampleData
def departments_data_raw
<<~DATA
department = Struct.new(:id, :name, keyword_init: true)
departments = [
OpenStruct.new(id: 1, name: 'Sales'),
OpenStruct.new(id: 2, name: 'Marketing'),
OpenStruct.new(id: 3, name: 'Finance')
department.new(id: 1, name: 'Sales'),
department.new(id: 2, name: 'Marketing'),
department.new(id: 3, name: 'Finance')
]
DATA
end

def departments_value_data_raw
<<~DATA
department = Struct.new(:id, keyword_init: true)
departments = [
OpenStruct.new(id: :sales),
OpenStruct.new(id: :marketing),
OpenStruct.new(id: :finance),
OpenStruct.new(id: :digital)
department.new(id: :sales),
department.new(id: :marketing),
department.new(id: :finance),
department.new(id: :digital)
]
DATA
end

def contact_types_data_raw
<<~DATA
contact_type = Struct.new(:value, keyword_init: true)
contact_types = [
OpenStruct.new(value: :email),
OpenStruct.new(value: :phone),
OpenStruct.new(value: :letter)
contact_type.new(value: :email),
contact_type.new(value: :phone),
contact_type.new(value: :letter)
]
DATA
end

def lunch_options_raw
<<~DATA
lunch_option = Struct.new(:id, :name, :description, keyword_init: true)
lunch_options = [
OpenStruct.new(
lunch_option.new(
id: 1,
name: 'Salad',
description: 'Lettuce, tomato and cucumber'
),
OpenStruct.new(
lunch_option.new(
id: 2,
name: 'Jacket potato',
description: 'With cheese and baked beans'
Expand All @@ -59,18 +63,19 @@ def grouped_lunch_options_raw

def primary_colours_raw
<<~DATA
colour = Struct.new(:id, :name, :description, keyword_init: true)
primary_colours = [
OpenStruct.new(
colour.new(
id: :cyan,
name: 'Cyan',
description: 'Greenish-blue'
),
OpenStruct.new(
colour.new(
id: :magenta,
name: 'Magenta',
description: 'Purplish-red'
),
OpenStruct.new(
colour.new(
id: :yellow,
name: 'Yellow',
description: 'Yellowy-yellow'
Expand Down Expand Up @@ -150,6 +155,7 @@ def custom_locale_config
def custom_error_presenter
eval(custom_error_presenter_raw)
end

# rubocop:enable Security/Eval

def form_data
Expand Down
Loading