Created
October 7, 2016 08:08
-
-
Save anonymous/6fb1fc8d18246a5873fe9f87c769e40b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Settings | |
DISCRIMINATOR = :type_name | |
TYPE_TO_CLASS = Hash[Setting.subclasses.map { |klass| [klass.type_name.to_s, klass] }].freeze | |
class SettingRepresenter < Representable::Decorator | |
include ::Representable::JSON | |
property :name | |
property DISCRIMINATOR, skip_parse: true | |
end | |
class MetaRepresenter < Representable::Decorator | |
include ::Representable::JSON | |
representer_selector = lambda |options| { # Irrelevant } | |
class_selector = lambda do |options| | |
type = options[:input][DISCRIMINATOR.to_s] | |
TYPE_TO_CLASS[type] || ::Theme::Settings::Setting | |
end | |
collection :groups, class: Group do | |
property :title | |
collection :sub_groups, class: SubGroup do | |
property :title | |
collection :settings, decorator: representer_selector, class: class_selector | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment