Class: Locomotive::Mounter::Reader::Api::SiteReader

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/mounter/reader/api/site_reader.rb

Instance Attribute Summary

Attributes inherited from Base

#items, #runner

Instance Method Summary collapse

Methods inherited from Base

#add_content_asset, #get, #initialize, #mounting_point

Constructor Details

This class inherits a constructor from Locomotive::Mounter::Reader::Api::Base

Instance Method Details

#readObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/locomotive/mounter/reader/api/site_reader.rb', line 8

def read
  super

  # get the site from the API
  site = self.get(:current_site)

  # set the default locale first
  Locomotive::Mounter.locale = site['locales'].first.to_sym

  Locomotive::Mounter::Models::Site.new(site).tap do |site|
    # fetch the information in other locales
    site.locales[1..-1].each do |locale|
      Locomotive::Mounter.with_locale(locale) do
        self.get(:current_site, locale).each do |name, value|
          next unless %w(seo_title meta_keywords meta_description).include?(name)
          site.send(:"#{name}=", value)
        end
      end
    end

    # set the time zone for the next Time operations (UTC by default)
    Time.zone = ActiveSupport::TimeZone.new(site.timezone || 'UTC')
  end
end

#safe_attributesObject



33
34
35
# File 'lib/locomotive/mounter/reader/api/site_reader.rb', line 33

def safe_attributes
  %w(name locales seo_title meta_keywords meta_description domains subdomain timezone created_at updated_at)
end