Skip to content

Commit

Permalink
Add values.yml and update seeding to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
KComrade53 committed Mar 21, 2024
1 parent 1a7c257 commit 7e1b2ee
Show file tree
Hide file tree
Showing 29 changed files with 101,565 additions and 76,373 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ $(STATIC_CHANGELOG_FILE):
# CLEAN
clean:
@$(NUKE) "Cleaning dev db" $(LOCAL_DB)
$(V)rm -f $(LOCAL_DB)
$(V)rm -f $(LOCAL_DB)*
@$(NUKE) "Cleaning Generated Docs" $(GENERATED_DOCS_PATH)
$(V)rm -f $(DOCS_GENERATED_SENTINEL)
$(V)rm -rf $(GENERATED_DOCS_PATH)
Expand Down
16 changes: 10 additions & 6 deletions app/serializers/data/property_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ def serialize(property)
end

def deserialize(hash)
Property.new(
id: hash["id"],
friendly_id: hash["friendly_id"],
name: hash["name"],
property_value_ids: hash["values"].map { _1["id"] },
)
Property.new do |u|
u.id = hash["id"]
u.friendly_id = hash["friendly_id"]
u.name = hash["name"]
u.property_value_ids = if hash["values_from"]
Property.find_by(friendly_id: hash["values_from"]).property_values.pluck(:id)
else
PropertyValue.where(friendly_id: hash["values"]).pluck(:id)
end
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/data/property_value_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ def serialize(property_value)
{
"id" => property_value.id,
"name" => property_value.name,
"friendly_id" => property_value.friendly_id,
}
end

def deserialize(hash)
PropertyValue.new(
id: hash["id"],
name: hash["name"],
friendly_id: hash["friendly_id"],
)
end
end
Expand Down
3 changes: 3 additions & 0 deletions bin/seed
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ require_relative "../application"
Application.establish_db_connection!
Application.load_and_reset_schema!

values_data = YAML.load_file("#{Application.root}/data/values/values.yml")
DB::Seed.values_from(values_data)

attributes_data = YAML.load_file("#{Application.root}/data/attributes/attributes.yml")
DB::Seed.attributes_from(attributes_data)

Expand Down

0 comments on commit 7e1b2ee

Please sign in to comment.