4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/binda/shopify/installer.rb', line 4
def create_settings_board values
raise ArgumentError.new 'You must provide an array or hash of settings values' unless values.is_a?(Array) || values.is_a?(Hash)
values = Hash[(CONNECTION_KEYS+STRUCTURES.keys).zip(values)] if values.is_a? Array
structure = ::Binda::Structure.find_or_create_by( name: 'Shopify Settings', slug: 'shopify-settings', instance_type: 'board' )
board = structure.board
field_settings = structure.field_groups.first.field_settings
CONNECTION_KEYS.each do |field_name|
field_value = values[field_name]
slug = [structure.slug, field_name.to_s.parameterize].join('-').gsub('_', '-')
field = field_settings.find_or_create_by( name: field_name.to_s.titleize, slug: slug, field_type: 'string' )
board.strings.find_or_create_by( field_setting_id: field.id ).update_attribute('content', field_value.strip)
end
STRUCTURES.keys.each do |structure_name|
field_value = values[structure_name]
slug = [structure.slug, structure_name.to_s.parameterize].join('-').gsub('_', '-')
field = field_settings.find_or_create_by( name: structure_name.to_s.titleize, slug: slug, field_type: 'string' )
board.strings.find_or_create_by( field_setting_id: field.id ).update_attribute('content', field_value.strip)
end
board
end
|