datocms / ruby-datocms-client

Ruby client for the DatoCMS API.
https://www.datocms.com/docs/content-management-api/using-the-ruby-client
MIT License
20 stars 15 forks source link

ItemsRepo#build_cache! is flawed when combined with I18n.with_locale #4

Closed ahoward closed 8 years ago

ahoward commented 8 years ago

tl;dr; if you switch locales the cache is the wrong locale.


I18n.enforce_available_locales = false

dato.available_locales.each do |locale|

  directory "data/dato/#{locale}" do
    I18n.with_locale(locale) do

      dato.send(:build_cache!)  # without this the cache will contain data for the wrong locale ;-/

      create_data_file "site.yml", :yaml, dato.site.to_hash

      dato.item_types.each do |item_type|
        create_data_file "#{item_type.api_key}.yml", :yaml, 
          dato.items_of_type(item_type).map(&:to_hash)
      end
    end
  end

end
stefanoverna commented 8 years ago

Thanks @ahoward for the report.. fixed by 1c6eb0ce, and released as v0.1.27

stefanoverna commented 8 years ago

The same commit also fixes the situation where an Item Type has a field called slug. In this case, the gem returns the directly the field value, and does not generate a slug on its own.