-
-
Save PavelPenkov/1d0b861239a1f81054dcf32abfe31e93 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 | |
TYPE_TO_CLASS = Hash[Setting.subclasses.map { |klass| [klass.name.underscore, klass] }].freeze | |
class SettingRepresenter < Representable::Decorator | |
include ::Representable::JSON | |
property :name | |
property DISCRIMINATOR, skip_parse: true, getter: lambda {|options| options[:represented].class.name.underscore } | |
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