diff --git a/lib/dato/dump/runner.rb b/lib/dato/dump/runner.rb index e98d484..deaf57b 100644 --- a/lib/dato/dump/runner.rb +++ b/lib/dato/dump/runner.rb @@ -18,13 +18,14 @@ def initialize(config_path, client, destination_path = Dir.pwd) def run loader.load + I18n.available_locales = loader.items_repo.available_locales + Dsl::Root.new( File.read(config_path), loader.items_repo, operation ) - I18n.available_locales = loader.items_repo.available_locales operation.perform end diff --git a/lib/dato/local/item.rb b/lib/dato/local/item.rb index 9a4eadb..b6e60b5 100644 --- a/lib/dato/local/item.rb +++ b/lib/dato/local/item.rb @@ -25,6 +25,9 @@ def ==(other) end def slug(prefix_with_id: true) + slug_field = fields.find { |f| f.api_key.to_sym == :slug } + + return read_attribute(:slug, slug_field) if slug_field return item_type.api_key.humanize.parameterize if singleton? return id.to_s unless title_field_api_key @@ -60,7 +63,7 @@ def fields end def attributes - @attributes ||= fields.each_with_object( + fields.each_with_object( ActiveSupport::HashWithIndifferentAccess.new ) do |field, acc| acc[field.api_key.to_sym] = send(field.api_key) @@ -92,7 +95,7 @@ def to_hash base[:position] = position if item_type.sortable - @attributes ||= fields.each_with_object(base) do |field, result| + fields.each_with_object(base) do |field, result| value = send(field.api_key) result[field.api_key.to_sym] = if value.respond_to?(:to_hash) diff --git a/spec/dato/local/items_repo_integration_spec.rb b/spec/dato/local/items_repo_integration_spec.rb index e0ac77e..a8171c4 100644 --- a/spec/dato/local/items_repo_integration_spec.rb +++ b/spec/dato/local/items_repo_integration_spec.rb @@ -44,7 +44,7 @@ module Local I18n.with_locale(:en) do expect(repo.articles.first.title).to eq "Title" - expect(repo.articles.first.to_hash[:title]).to eq "Titolo" + expect(repo.articles.first.to_hash[:title]).to eq "Title" end end end