Module: Meta::JsonSchema::SchemaOptions::UserOptions

Defined in:
lib/meta/json_schema/support/schema_options.rb

Constant Summary collapse

Common =
Utils::Kwargs::Builder.build do
  key :stage
  key :scope, normalizer: ->(value) {
    raise ArgumentError, 'scope 选项不可传递 nil' if value.nil?
    value = [value] unless value.is_a?(Array)
    value.map do |v|
      # 只要加入了 Meta::Scope::Base 模块,就有与 Meta::Scope 一样的行为
      next v if v.is_a?(Meta::Scope::Base)

      # 将 v 类名化
      scope_name = v.to_s.split('_').map(&:capitalize).join
      # 如果符号对应的类名不存在,就报错
      if !defined?(::Scopes) || !::Scopes.const_defined?(scope_name)
        raise NameError, "未找到常量 Scopes::#{scope_name}。如果你用的是命名 Scope(字符串或符号),则检查一下是不是拼写错误"
      end
      # 返回对应的常量
      ::Scopes.const_get(scope_name)
    end.compact
  }

  handle_extras :merged
end
ToDoc =
Utils::Kwargs::Builder.build(Common) do
  key :schema_docs_mapping, :defined_scopes_mapping
end
Filter =
Utils::Kwargs::Builder.build(Common) do
  key :discard_missing, :exclude, :extra_properties, :type_conversion, :validation
  key :execution, :user_data, :object_value
end