Sha256: 3a19a1f9f972254a0cbdc6dfa806b7491cefbb833fcd7ba1ec7af48d9c44d1de
Contents?: true
Size: 1.82 KB
Versions: 4
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true require 'forwardable' require 'active_support/inflector/transliterate' require 'active_support/hash_with_indifferent_access' require 'agave/utils/locale_value' module Agave module Local class Site extend Forwardable attr_reader :entity def_delegators :entity, :id, :name, :locales, :domain, :no_index, :production_frontend_url def initialize(entity, items_repo) @entity = entity @items_repo = items_repo end def global_seo read_attribute(:global_seo, FieldType::GlobalSeo, locales.size > 1) end def theme read_attribute(:theme, FieldType::Theme, false) end def favicon read_attribute(:favicon, FieldType::File, false) end def to_s "#<Site id=#{id} site_name=#{name}>" end alias inspect to_s def favicon_meta_tags(theme_color = nil) Utils::FaviconTagsBuilder.new(self, theme_color).meta_tags end def to_hash attributes = [ :id, :name, :locales, :theme, :domain, :no_index, :global_seo, :favicon, :production_frontend_url ] 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 obj = entity.send(method) || {} Utils::LocaleValue.find(obj) else entity.send(method) end type_klass.parse(value, @items_repo) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
agave-client-0.1.3 | lib/agave/local/site.rb |
agave-client-0.1.2 | lib/agave/local/site.rb |
agave-client-0.1.1 | lib/agave/local/site.rb |
agave-client-0.1.0 | lib/agave/local/site.rb |