Class: JSON::Schema::Lite::Block

Inherits:
Hash
  • Object
show all
Defined in:
lib/json/schema/lite/block.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Block

Returns a new instance of Block.



6
7
8
# File 'lib/json/schema/lite/block.rb', line 6

def initialize(&block)
  self.instance_eval &block
end

Instance Method Details

#array(key, *args, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/json/schema/lite/block.rb', line 17

def array(key, *args, &block)
  prop = {
    type: :array
  }
  if block_given?
    prop[:items] = self.class.new(&block)
  else
    prop[:items] = { type: args[0] }
    if args.size >= 2 && args[1].is_a?(Hash)
      option = args[1]
      add_required key if option[:required]
    end
  end
  set_properties key, prop
end

#object(key, &block) ⇒ Object



33
34
35
# File 'lib/json/schema/lite/block.rb', line 33

def object(key, &block)
  set_properties key, self.class.new(&block)
end