# Helper class to create a custom `Parser` # @example Example of usage: # class Custom::Parser::LoginProviders < Eco::API::Custom::Parser # attribute "login_provider_ids" # # active_when_any "some-field1", "some-field2" # optional # parsing_phase :final # optional, default is (default :internal) # serializing_phase :final # optional, it will be (default :person) # # def parser(hash, deps) # get_values(hash).map do |name| # login_providers.to_id(name&.downcase.strip) # end.compact # end # # def serializer(hash, deps) # if ids = hash["login_provider_ids"] # login_providers.to_name(ids) # else # [] # end # end # # private # # def get_values(hash) # value, field1, field2 = hash.values_at("login_provider_ids", "some-field1", "some-field2") # return value if value # at the :final parsing phase, login_provider_ids is already an Array # some_logics(field1, field2) # end # # def some_logics(a, b) # case a # when "staff" # ["Company SSO"] # when "contractor" # ["Password"] # elsif b # return ["Password"] if b.end_with?("Owner") # ["Password", "Company SSO 2"] # end # end # # def login_providers # @login_providers ||= ASSETS.config.login_providers # end # # end class Eco::API::Custom::Parser < Eco::API::Common::Loaders::Parser end