Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Fix I18n whines and avoid attributes memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Sep 13, 2016
1 parent 66cef9e commit 1c6eb0c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/dato/dump/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions lib/dato/local/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion spec/dato/local/items_repo_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c6eb0c

Please sign in to comment.