Class: Meta::JsonSchema::ObjectSchemaBuilder::WithCommonOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/meta/json_schema/builders/object_schema_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder, common_options) ⇒ WithCommonOptions

Returns a new instance of WithCommonOptions.



59
60
61
62
63
64
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 59

def initialize(builder, common_options, &)
  @object_schema_builder = builder
  @common_options = common_options

  instance_exec(&) if block_given?
end

Instance Attribute Details

#common_optionsObject (readonly)

Returns the value of attribute common_options.



57
58
59
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 57

def common_options
  @common_options
end

#object_schema_builderObject (readonly)

Returns the value of attribute object_schema_builder.



57
58
59
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 57

def object_schema_builder
  @object_schema_builder
end

Class Method Details

.merge_options(common_options, options) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 75

def self.merge_options(common_options, options)
  common_options.merge(options) do |key, oldVal, newVal|
    if key == :scope
      # 合并 common_options 和 options 中的 scope 选项
      Scope::Utils.and(oldVal, newVal)
    else
      # 关于 param、render 内部选项的合并问题暂不考虑
      newVal
    end
  end
end

Instance Method Details

#merge_options(options) ⇒ Object



71
72
73
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 71

def merge_options(options)
  self.class.merge_options(common_options, options)
end

#property(name, options = {}, &block) ⇒ Object



66
67
68
69
# File 'lib/meta/json_schema/builders/object_schema_builder.rb', line 66

def property(name, options = {}, &block)
  options = merge_options(options)
  object_schema_builder.property(name, options, &block)
end