Sha256: 9c413a4abdbba0d872dfe053402dd2f2669ed46cab8c3e90cbc69fed1e3e9e9d
Contents?: true
Size: 1.52 KB
Versions: 14
Compression:
Stored size: 1.52 KB
Contents
# frozen_string_literal: true require 'forwardable' require 'active_support/inflector/transliterate' require 'active_support/hash_with_indifferent_access' module Dato module Local class Site extend Forwardable attr_reader :entity def_delegators :entity, :id, :name, :locales, :theme_hue, :domain, :internal_domain, :no_index def initialize(entity) @entity = entity end def global_seo read_attribute(:global_seo, FieldType::GlobalSeo, locales.size > 1) end def favicon read_attribute(:favicon, FieldType::Image, false) end def to_s "#<Site id=#{id} site_name=#{site_name}>" end alias inspect to_s def to_hash attributes = [ :id, :name, :locales, :theme_hue, :domain, :internal_domain, :no_index, :global_seo, :favicon ] attributes.each_with_object({}) do |attribute, result| value = send(attribute) result[attribute] = if value.respond_to?(:to_hash) value.to_hash else value end end end private def read_attribute(method, type_klass, localized) value = if localized (entity.send(method) || {})[I18n.locale] else entity.send(method) end value && type_klass.parse(value, @items_repo) end end end end
Version data entries
14 entries across 14 versions & 1 rubygems